Jump to content

Counting rows and displaying row number


richrock

Recommended Posts

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

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++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.