For some reason I’m having a problem retrieving data from my database. It leaves off the first item being listed.
$sql=mysql_query("SELECT * FROM students WHERE (year = '" . mysql_real_escape_string($_SESSION['year']) . "') and ( branch= '" . mysql_real_escape_string(($_SESSION['branch'])). "') ");
$data=mysql_fetch_array( $sql );
print "<table>"
while($data = mysql_fetch_array( $sql ))
{
Print "<tr><td>".$data['idno']." </td><td>".$data['name'] . " </td></tr>";
}
print "</table>"
Please help me with this. Thank you.
Remove the following line:
The call to
mysql_fetch_arraymoves the internal pointer to the next row, thus you are getting all rows except the first in yourwhileloop.You could also reset the internal pointer with
mysql_data_seek.