Today’s tutorial expounds upon a previous tutorial.  Not long ago, we covered the necessary API call and steps to retrieve the total number of CCB profiles.

The title of this tutorial might be a little confusing based on the previous tutorial.  Why in the world are we covering this tutorial?  Let me explain.

The previous tutorial will return the same value as this tutorial.  However, there are differences between the two tutorials, such as the following:

  • The amount of time it takes both to execute and return the total number of profiles
  • The previous tutorial allows access to individual detail (i.e., first name, last name, etc.) whereas today’s tutorial does not return individual detail
  • Today’s tutorial focuses on returning only the valid individuals and not inactive individuals like the previous tutorial

Today’s tutorial is drastically reduces the time it takes to arrive at the total number valid individuals by using the valid_individuals API service.

I’m not getting into the nitty-gritty details pertaining to the existing variables and functions used. Although not needed for this tutorial, don’t forget to set the XPath query expression to the following: //valid_individuals/valid_individual.

There are a few new lines that have added been to account for the total number of valid individuals (see below). Use the built-in PHP methods: count and sizeof to achieve the total number of valid individuals.  Since the nodes variable is nothing more than the XML array, we use the aforementioned PHP methods that are best for totaling arrays.

<?PHP

//count() or sizeof() will return the total number
$nodesCountA = count($nodes); 
$nodesCountB = sizeof($nodes); 

$response_object .= '<p>A: '.$nodesCountA.' | B: '.$nodesCountB.'</p>';

?>

Well, that’s it for this tutorial, and below is the code you’ve been waiting for.  Now, save it to a php file, upload and execute it.

Enjoy the reduced time it takes to retrieve the total number of valid individuals.  Stay tuned… more tutorials to post in the coming weeks.

<?PHP

// contains resusable globals and functions
include("includes/config.php");

$apiService = 'valid_individuals'; // CCB api service

$urlData = array_filter( array(
	'srv' => "$apiService"
	) );

$rss = ccbDetails('get',$urlData); // transform to XML

$nodes = $rss->xpath('//valid_individuals/valid_individual');  // xpath for individuals->individual

$response_object = '';

//count() or sizeof() will return the total number
$nodesCountA = count($nodes); 
$nodesCountB = sizeof($nodes); 

$response_object .= '<p>A: '.$nodesCountA.' | B: '.$nodesCountB.'</p>';

foreach ($nodes as $node)
{
    $response_object .= 'Individual Id: '.$node['id'].'<br/>';  // now print the api status information (See CCB API documentation for more $apiService fields)
}

echo $response_object;

?>

 

Related Posts

Subscribe and receive the following...

  • Inside CCB tips and tricks
  • Instant CCB tutorial alerts and updates
  • CCB How To's, Videos, Webinars and more...