CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> Archive -> GotoCode Archive

 counting records in a directory

Print topic Send  topic

Author Message
Pierrot
Posted: 04/14/2003, 6:39 AM

Hello
I have a problem with counting records inside a directory.
I have 2 tables in my db, category and events. The category table is a tree (so there are categories and subcategories), and each event belongs to 1 category.
With CCS, i've built a directory structure for my category table. But i would like to show the number of events related to each subcategory like this :

Category1
Sub11 (32)
Sub12 (13)
Sub13 (23)
Category2
Sub21 (34)
Sub22 (5)
...

Does anyone feel able to help me ? I spent hours on this problem, but since the directory deals with the category table, i can't count the corresponding rows in the events table.
Thanks a lot for all your help.

Pierrot
Frank
Posted: 04/14/2003, 1:18 PM

Hi read this :
http://www.gotocode.com/art.asp?art_id=230&art_content_...Article_Page=1&
Donald
Posted: 04/14/2003, 1:27 PM

Here's an example with the directory !

http://www.rexdesign.com/ccs/kb.php?language_id=1
lneisius
Posted: 08/08/2003, 9:25 PM

I can't find the directory example on rexdesign, could someone help?
DaveRexel
Posted: 08/09/2003, 10:41 AM

::
here's

http://www.rexdesign.com/ccs/kb.php?language_id=7&category_id=42

the main link and searching for the word "count" in the site header search-box returns this

http://www.rexdesign.com/ccs/SearchResults.php?s_keyword=count
(Free registration required)

Please post back here so others can benefit from a possible solution.

Dave
lneisius
Posted: 08/11/2003, 2:10 PM

The only thing I can find on rexdesign is edit directory page with directory component. Where is the directory component with counters?
DaveRexel
Posted: 08/11/2003, 3:18 PM

::
Here's 3 tutorials with short and easy to follow event snippets that are hopefully simple enough to port to any language :

http://www.rexdesign.com/ccs/kb.php?language_id=7&category_id=42

Dave
DaveRexel
Posted: 08/11/2003, 3:25 PM

::
Since those tutorials were written I have another approach that's simpler to port :

- In CCS DESIGN-MODE add Label component with no DB-source right next to the SubDirectory component already on the page

- Do a DB-lookup in this Label before Show[Row] event that returns the count needed eg SELECT COUNT(SubXX) (Look at your Directory components SQL for hints)

- Set the the Label display value to the DB-value

That 3-step method is what I currently use on the Tutorials page Directory on the site.

Dave

lneisius
Posted: 08/12/2003, 5:28 AM

I've tried the following with nothing but errors (Variable undefined 'cat_CategoryID'):

CCDLookUp("Count(*)","YellowPages","CategoryID=" &CCToSQL(cat_CategoryID,"Integer"),DBYellowPages)

This should be the correct code from previous versions of the directory component.

I am new to this and need some help on identifying the variable that should be used. When I look at the code that creates the categories I see a number of recordsets and arrays should I be using one of these items instead of cat_CategoryID? Is cat_CategoryID the correct variable? Any help would be greatly appreciated as I am new to this.
DaveRexel
Posted: 08/12/2003, 12:44 PM

::
Being rather pressed for time right now I hope the following snippet from the live site code will

1 help
2 be easy to port to other technologies

The forum is sure to destroy the formatting but I'll try to comment the salient logic :

Unfortunately I cannot provide a screenshot here but for the test please add

1- Standard CCS Directory Component named "yourDirectoryName"
2- add a Template variable placing it just beside the SubcategoryLink in Design-Mode
(Tip: surround the tag with superscript <sup> html-tag (manual code not by clicking on icon) as most visual editing seems to fry the component after a few edits.

## example used in code snippet is named {artCount}

## (HOPE THE ## COMMENTS WILL HELP WITH PORTING)

## FOR PHP TO ADDRESS THE TEMPLATE
global $Tpl;
## THE DIRECTORY COMPONENT
global $yourDirectoryName;
## DB INIT
$conn = new clsDBinternet();
## GRAB A FEW VALUES FROM VARIOUS PLACES
$product_id = CCGetParam("product_id", 1);
$category_id = CCGetParam("category_id", 0);
## MOST IMPORTANT === MATCH YOUR SQL QUERY
## TO BE SIMILAR TO GENERATED DIRECTORY SUBCAT QUERY
## IF YOUR COUNT DISPLAY IS TO MATCH YOUR SUB-CAT
$myCountSQL = "SELECT COUNT(*) FROM yourTable "
." WHERE product_id="
. $product_id
." AND category_id="
. $category_id
." ";
## CHECK WHAT YOU'VE COUNTED
$myRecordsCount = CCGetDBValue($myCountSQL, $conn);
if ($myRecordsCount == 0)
{
## SQUASH ZERO-BASED DISPLAY
$Tpl->SetVar("artCount", "");
}
else
{
## SET TEMPLATE VAR TO YOUR COUNT
$Tpl->SetVar("artCount", " ".$myRecordsCount."<br>");
}
## SHOWS A INT RETURNED FROM COUNTING
## THE RECORDS IN A CURRENT SUB-DIRECTORY
## IN DIRECTORY COMPONENT BASED ON THE
## CURRENT INPUT PARAMETERS

Phew... glad to get out of comment mode :-)

Like I said the example is taken from live code so your SQL and parameter needs will most likely be different but the logic is simple.

However I must say that the pitfalls can be deep when trying to twist the CCS Directory to your needs : I would say it needs extention and refinement in the next release.

I'm still searching for how to influence the second stage of the Directory Component === right after you click on Main Category you get another display generated by CCS, I'm trying to identify points of influence there for an idea I have... will appreciate any info on 2nd stage display mode while we're on the subject of CCS Directory Components.

Dave

   


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

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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