Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.