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 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
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: [Jason] Simple Products Total
By mark99 - April 25, 2010 - edited: April 25, 2010
Let's say my section is called 'big_test' (full table name of the section would be 'cms_big_test'), then within that I have the fields.. of which one is called 'category', and within category I have a checkbox list of individual entrys like 'red cats', 'blue dogs' etc. for the actual categories.
So based on your example.. 'products' would change to 'big_test', 'category' would stay the same because thats what I've called my category field and then [font "Verdana"]$categoryNum would become something like 'red cats' (albeit with $categoryNum being defined as a separate variable on the above line [$categoryNum="red cats";]. Tried that, didn't work.
Re: [mark99] Simple Products Total
By Perchpole - April 26, 2010
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