WANT TO SHOW A RECORD COUNT ON YOUR WEB PAGE - Dec 10th, 2016
|
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 (like field value not = "banana") , 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'] != 'banana'): ?><?php $count++; ?><?php endif ?>
If you just want to list records with contents in a field, use this instead
<?php $count = 0; ?><?php foreach ($my tableRecords as $record): ?<?php if ($record['your field'] ): ?><?php $count++; ?><?php endif ?>
And where I want to display the count:
There are <?php echo $count ?> records
Another approach suggested by Jason Sauchuk from Interactive Tools, is:
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 ?>
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.