Ariful Islam
Ariful Islam

Reputation: 7675

While loop with mysql_fetch_array() in PHP

Recently in one of my project i wrote the following code for retrieving and print data from database.

$query = "select * from tblteachers limit 0, 4";
$result= mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result)>0)
{   
    while($fetchRow=mysql_fetch_array($result, MYSQL_BOTH))
    {
      echo $fetchRow['id'];
    }
}

in the tblteachers table there are 14 row and the query get 4 row but the problem is it print 3 row by missing the first row. that is it print 2, 3, 4.

Upvotes: 0

Views: 624

Answers (1)

Roy Toledo
Roy Toledo

Reputation: 643

you might have used something that moved the pointer. try adding mysql_data_seek($result,0); before the while statement

Upvotes: 1

Related Questions