Jump to content

Get number of clients


wdele

Recommended Posts

this won't specifically tell you how to do it via API, but if you want to use PHP to create a smarty variable, you might take a look at the thread below...

 

http://forum.whmcs.com/showthread.php?86718-Is-there-s-smarty-syntax-to-display-total-of-clients

 

Nice! But the problem is that I need to show it on my website (WordPress) because my main website is not powered by WHMCS. How would I go about that?

Link to comment
Share on other sites

Indirectly you can get this number probably iterating GetClients API function and counting keys but to me it seems a very bad solution. What if you have 2000 clients in your WHMCS? Spamming GetClients for every single visitor on your website and every page view sounds stupid.

 

The best way for me is very simple. Make a php script on WHMCS, include DB connection, query database to COUNT() tblclients and print the resulting number. Now on Wordpress call this file (a get content should be fine) and job done. You have your number. This solution is better because it's faster and doesn't overload without a valid reasons WHMCS and your webserver. Personally I'll also cache this value.

Link to comment
Share on other sites

Create a file, in the root of your WHMCS, called "clientcount.php". Within that file, put the following code:

 

<?php

require("init.php");

// Get the client count
$table = "tblclients";
$fields = "COUNT(*) AS clientcount";
$result = select_query($table,$fields);
while ($data = mysql_fetch_array($result)) {
 $clientcount = $data['clientcount'];
}

echo $clientcount;

?>

 

Now you can call this externally, by using the following code:

 

<?php

$clientcount = file_get_contents('http://www.yourdomain.com/clientcount.php'); // Full URL to clientcount.php
echo 'Total Number of Clients: ' . $clientcount;

?>

 

Hopefully, that helps.

Link to comment
Share on other sites

  • 5 years later...

As this is Googles first answer for whmcs get clients. For wordpress we wrote the following to get ours working, allowing us to tie it into a shortcode as well:

//WHMCS Get Clients Shortcode
//Written by Kyle - www.blacknovadesigns.co.uk
function bnd_whmcs_get_clients_shortcode() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://YOUR-DOMAIN-WHERE-WHMCS-IS/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'GetClients',
            'username' => 'API-TOKEN-ID',
            'password' => 'API-TOKEN-PASSWORD,
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$results = json_decode($response, true);
curl_close($ch);

echo "<h3>" .$results['totalresults']. "</h3>";
echo "<p>HAPPY CLIENTS</p>";
}
add_shortcode( 'whmcsgetclients', 'bnd_whmcs_get_clients_shortcode' );

Hopefully this will help for anyone looking to do this them selves in the future.

Edited by BlackNovaDesigns-Kyle
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated