Reputation: 5419
I'm having trouble iterating through MySQL rows. This is my current code:
$query = "SELECT * FROM translations
WHERE iddoc = '$id'
AND submitted = 1;";
$result= mysqli_query($query);
$numrows = mysqli_num_rows($result);
$row2 = mysql_fetch_row($result);
if ($numrows > 0) {
while($eachrow = mysqli_fetch_array($result, MYSQLI_NUM)) {
echo $eachrow[0];
echo ", ";
echo $numrows;
}
}
The result of this is:
6, 2
But if there are 2 rows, why is the while loop ending after only 1 iteration? What am I understanding wrong?
EDIT: It appears to be displaying ONE LESS than the correct amount of rows. I.E. the while loop is running 1 less time than it should.
Upvotes: 0
Views: 1624
Reputation: 5419
Found problem. I was fetching the first row with
$row2 = mysql_fetch_row($result);
outside of the while loop, thus causing it to start on the second row and skip over the first.
Upvotes: 3