I have the following code:
if ($user) {
$highscore = mysql_result(mysql_query("SELECT Score FROM HighScore WHERE fbID = $user"),0);
if (empty($highscore)) { //if no result
echo '<div id="uhs">0</div>';
} else {
echo '<div id="uhs">'. $highscore .'</div>';
}
} else {
echo '<div id="uhs">0</div>';
}
When I get no result from the db (because there is no Score), it should echo: echo '<div id="uhs">0</div>'; but it doesn’t. Instead I get the error: MySQL error: Unable to jump to row 0 on MySQL result index 8. I thought using: if (empty($highscore)) should take care of it when having no result.
What am I doing wrong and how to fix it, it works fine when there is a Score in the db
Many thanks
The function
mysql_num_rows()is used to check ifmysql_queryreturned any result.