richrock Posted September 22, 2008 Share Posted September 22, 2008 Okay, this is probably a: dead easy and b: not using COUNT(*). I am displaying the results of a search, where a client is searched for, and all items owned/sold by that client are displayed in a table. However, I need to count and display each result as: 1. Product one 2. Product two etc... I can't use ID as there are gaps inbetween each result (this is filtering 900+ items down to about 3 or 4. So how do I get PHP to return each row as 1,2,3,4,5,6,7,etc... All the searches give me details of how to count total rows in mysql (SELECT COUNT(*) FROM table;) Rich Link to comment https://forums.phpfreaks.com/topic/125296-counting-rows-and-displaying-row-number/ Share on other sites More sharing options...
JonnoTheDev Posted September 22, 2008 Share Posted September 22, 2008 Set a loop counter when displaying the results. This is an example - fit into your own loop. $results = array('product 1', 'product 2', 'product 3'); $itemNum = 1; foreach($results as $product) { print $itemNum.". ".$product."<br />"; $itemNum++; } Link to comment https://forums.phpfreaks.com/topic/125296-counting-rows-and-displaying-row-number/#findComment-647684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.