Display number of items on list page

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

By Toledoh - March 31, 2011

Hi Guys.

I'm sure I've seen this, but cant find the answer.

I've got a number of listings, and each listing has a "type" field that calls from another table - 'product_types'.

I then have a list view of the 'product_types' which in turn link, ie.


<?php foreach ($product_typesRecords as $record): ?>
<a href="results.php?type=<?php echo $record['num'] ?>"><?php echo $record['title'] ?></a>
<?php endforeach ?>


My question is, can I display the number of items within that link? ie.
<?php foreach ($product_typesRecords as $record): ?>
<a href="results.php?type=<?php echo $record['num'] ?>"><?php echo $record['title'] ?></a> [XXX Items for sale]
<?php endforeach ?>

Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Display number of items on list page

By Jason - March 31, 2011

Hi Tim,

Another way to go about this would be to use the function mysql_select_count_from(). This allows you to set a table name and a where clause. The function will then return the number of records that meet that where clause.

For example, let's assume you're storing all your items for sale in a table called "items". This table has a field called "type" whose value is the "num" field that you're outputting on your list page. You can then use the function to display how many items you have for each type like this:

<?php foreach ($product_typesRecords as $record): ?>
<a href="results.php?type=<?php echo $record['num'] ?>"><?php echo $record['title'] ?></a> [<?php echo mysql_select_count_from('items', "type ='".$record['num']."'");?> Items for sale]
<?php endforeach ?>


Hope this helps
---------------------------------------------------
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] Display number of items on list page

By Toledoh - April 5, 2011

Sorry Jason - just realised I hadn't replied.... works a treat. Thanks!
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Display number of items on list page

By Jason - April 6, 2011

Hi Tim,

No problem. Glad that's working for you!
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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