The following will print out 9 rows however there are acutually 10 rows in the fetch array. The first one is always missing. Any clue why it skips the first $row? Thank you.
// Fetch and print all the records....
$bg = '#99cccc';
while($row = sqlsrv_fetch_array($result)) {
$bg = ($bg=='#99cccc' ? '#ffffff' : '#99cccc');
echo '<tr bgcolor="' . $bg . '">
<td align="left">'. $row['LastName'] . '</td>
<td align="left">' . $row['ItemId'] . '</td>
<td align="left">' . $row['Description'] . '</td>
<td align="left">' . number_format($row['ListPrice'],2) . '</td>
<td align="left">' . $row['ItemStatus'] . '</td>
<td align="left">' . $row['DateTimePosted'] . '<br /></td>
</tr>
';
} // End of WHILE loop.
sqlsrv_fetch_array missing the first row
Moderator: General Moderators
Re: sqlsrv_fetch_array missing the first row
My guess is that something is moving the result pointer before you call sqlsrv_fetch_array...
When you execute a query (e.g., with mysql_query), the result pointer starts on index 0 (row 1), but various functions will move the pointer. For example:
When you execute a query (e.g., with mysql_query), the result pointer starts on index 0 (row 1), but various functions will move the pointer. For example:
Code: Select all
$q = mysql_query("SELECT * FROM table LIMIT 10"); // assume result is 10 rows, result pointer is on index 0
$r1 = mysql_result($q,2,'id'); // id of 2nd index (3rd result), pointer is now on index 3
$r2 = mysql_fetch_assoc($q); // calling without a while statement... moves the pointer by one, now we're on index 4
$r3 = mysql_fetch_assoc($q); // and now on index 5
while($r = mysql_fetch_assoc($q)) {
echo $r['id'].'<br>'; // result indexes 5,6,7,8,9
}Re: sqlsrv_fetch_array missing the first row
thank you for the clue... that's what happened. Everything fixed.
Re: sqlsrv_fetch_array missing the first row
I have the statement:
$sold_array = sqlsrv_fetch_array ($result);
Before the while loop which must put the pointer ahead 1
Is there a way to reset the pointer to the beginning?
$sold_array = sqlsrv_fetch_array ($result);
Before the while loop which must put the pointer ahead 1
Is there a way to reset the pointer to the beginning?