×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Get Row Number in MySQLi

Get Row Number in MySQLi

Get Row Number in MySQLi

(OP)
How can I get the row number in a list of entries? It's not the number of rows in the result that I need: it is a line by line count of each one.

RE: Get Row Number in MySQLi



MySQL doesn't have 'row numbers' per se, the records returned are simply an array, going from 0 to (count - 1), in whatever sort order was specified in the query.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Get Row Number in MySQLi

(OP)
That's what I thought. I'm trying to create a function to provide the row number when run inside a loop so how would I do it? I'm not sure where to begin.

RE: Get Row Number in MySQLi

Quote:

That's what I thought. I'm trying to create a function to provide the row number when run inside a loop so how would I do it? I'm not sure where to begin.

Can you not just add a counter?


For example:

CODE

$rowNumber = 1;
while($row=mysqli_fetch_row($result))
{
echo $rowNumber . $row['fieldname'];
$rowNumber++; }

This will increase $rownumber by one each time a row is echoed out.

Or is there something else you are trying to accomplish?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Get Row Number in MySQLi

(OP)
Thank you, that is exactly what I was looking for!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close