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 gkornbluth - March 31, 2011 - edited: March 31, 2011

Hi Tim,

Here’s a recipe from the CMSB Cookbook http://www.thecmsbcookbook.com that might help.

WANT TO SHOW A RECORD COUNT ON YOUR WEB PAGE


You can use this to see the total number of records displayed:

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

There are a few other variables that can be used besides “totalRecords”. You can list them all with this code:

<xmp><?php print_r($your_table_nameMetaData); ?></xmp>


Here's another approach to counting the number of records in a particular category. (change the "if" criteria to suit your needs, and if you're using more than one counter on your page, change $count to some unique name, like $count2, or $count3),

First set a counter to zero.
Then in your "foreach" loop, if a record meets a particular set of criteria, increment the counter by 1 for each record that meets that criteria.
Finally, display the record count.

<?php $count = 0; ?><?php foreach ($my tableRecords as $record): ?<?php if ($record[your field'] != 1): ?><?php $count++; ?>

And where you want to display the count:

There are <?php echo $count ?> records

Hope that gives you some ideas.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

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/