Q
Problem solve Get help with specific problems with your technologies, process and projects.

Adding row numbers to PHP code

MySQL expert Mike Hillyer recommends a shortcut for adding row numbers to PHP code when attempting to access and retrieve data.

Is there any facility to number the output when retrieving data from a database using PHP? For example: 1.output1, 2.output2, and 3.output3

While you could, perhaps, develop a way to generate a row number in a query, it should not be necessary to have a row number at query time. Many users have row ID values stored in their tables to assist with joins and where clauses. Others add row numbers at display time to help users distinguish rows, but PHP should not require row numbers to properly process data.

In any case, as MySQL does not have a row number meta-column, it would be better to add a row number in your PHP code while iterating rows by way of a counter or similar method.

Next Steps

How to fine-tune PHP

Dig Deeper on Linux servers

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

SearchServerVirtualization

SearchCloudComputing

Close