CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Tip: Directory Builder, counting categories and subcategories

Print topic Send  topic

Author Message
lvalverdeb

Posts: 299
Posted: 10/06/2004, 4:44 PM

If you need to display the number of categories and subcategories in a Directory form generated by the Directory Builder:

  
function writeChildrenCountToLink(&$Link,$Connection,$Table,$ParentField,$Param) {  
	// e.g writeChildrenCountToLink($yourform->CategoryLink,new clsDB...(),"directory_table","parent_id","category_id");  
	// Save original link value  
	$CurText = $Link->GetValue();  
	$CurLink = $Link->Parameters;  
	$paramArray = explode("&",$CurLink);  
	$myParam = null;  
	$myParamValue = null;  
	//find our $Param in the link parameters  
	foreach ($paramArray as $item)	{  
		if (substr($item,0,strlen($Param)) == $Param)	{  
			$myParam = substr($item,0,strlen($Param));  
			$myParamValue = substr($item,strlen($Param)+1,strlen($myParam));  
		}  
	}		   
	if ($myParam != null && $myParamValue != null) 	{  
		// if our parameter and its corresponding value were found then compute the count and modify the link text  
		$Result = CCDLookUp("count(*)",$Table,$ParentField."=".$Connection->ToSQL($myParamValue,ccsInteger),$Connection);  
		$Link->SetValue($CurText."(".$Result.")");  
	}  
	return $Link;  
}  

Using the Directory example in the sample pack:
1) Place the above function in the Common.php
2) In the BeforeShowCategory event, place the following code:

global $yp_categories,$DBInternetDB;
writeChildrenCountToLink($yp_categories->CategoryLink,$DBInternetDB,"directory_categories","category_id_parent","category_id");

3) In the BeforeShowSubCategory event, place the following code:
global $yp_categories,$DBInternetDB;
writeChildrenCountToLink($yp_categories->SubcategoryLink,$DBInternetDB,"directory_categories","category_id_parent","category_id");

Regards

Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4
View profile  Send private message
Karsten


Posts: 57
Posted: 10/08/2004, 4:59 PM

hi Ivalerdeb,

cool, thanks to provide your code to others,
this is a great example for ALL CCS developers to follow.

thx Ivalerdeb!

_________________
If one gives up, he told himself he failed.
View profile  Send private message
datadoit.com
Posted: 03/22/2005, 3:56 PM

How can this be configured to get the number of items in a particular
category or subcategory?


lvalverdeb

Posts: 299
Posted: 03/27/2005, 7:56 AM

Hi, I just posted a re-write of the function in the Tips and Solution forum. If I understood your question correctly:
  
$myCategory = 10;  
$tmp = new DirectoryCount($DBInternetDB,"directory_categories","category_id_parent","category_id");  
$ChildrenCount = $tmp->getChildrenCount($myCategory);  
unset($tmp);  

Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.