Simple Products Total

5 posts by 3 authors in: Forums > CMS Builder
Last Post: April 26, 2010   (RSS)

By mark99 - April 23, 2010 - edited: April 23, 2010

I'd like to display a total on my viewer page for how many products there are in total over the various paginated pages for my particular category, how do I do it? Under the old CGI Listings script I could just use $mcount$.

I must stress that this should not be a total for all the products in my database, just for the products being displayed within any given criteria (category etc.) on the viewer page.

Re: [mark99] Simple Products Total

By Jason - April 23, 2010

Hi,

Try this:

<?php
$where="category=".mysql_escape($categoryNum);
$count = mysql_select_count_from('products',$where);
?>


In this code, you would change 'products' to the name of your products table. 'category' would change to the name of the category field in the "products" table. Finally, change $categoryNum to the variable storing the category that you are currently displaying.

After this code executes, $count will hold a count of all the records in the products table that have the specified category.

Give that a try and let me know if you run into any issues.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [mark99] Simple Products Total

By Perchpole - April 26, 2010

Hi, Mark99

I don't know if it will work in your particular case but I always use this bit of code to count the number of records:

<?php echo $itemMetaData['totalRecords']; ?>

Where item corresponds to the record list at the top of your page, eg:

list($itemRecords, $itemMetaData) = getRecords(array(
'tableName' => 'item',
));


:0)

Perch

Re: [Perchpole] Simple Products Total

By mark99 - April 26, 2010

Ah that worked :)