mysql_num_rows and limit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

stukov
Forum Commoner
Posts: 26
Joined: Sun Jul 24, 2005 2:16 pm
Location: Sherbrooke, Qc, Canada

Post by stukov »

No. As I said before, mysql_fetch_array will only extract you one row of your result (resource) and put it into an array. If you want to store all of them, walk trough your result set with a while loop with something like this :

Code: Select all

while ($row = mysql_fetch_assoc($result)) {
   echo $rowї&quote;userid&quote;];
   echo $rowї&quote;fullname&quote;];
   echo $rowї&quote;userstatus&quote;];
}
So, by doing :

Code: Select all

$array = mysql_fetch_array($query);
you will get only the first row MySQL returned you. If you want to pick the 83rd row, you will have to use mysql_data_seek(). It will move the internal row pointer to the row you want to select. Then, by calling mysql_fetch_array() you will select this row.

Manual page: http://ca3.php.net/manual/en/function.m ... a-seek.php

By the way, mysql_fetch_row, mysql_fetch_array and mysql_fetch_array work pretty the same. Only the way you store the return value changes.
Post Reply