Admin Life Errors, Fixes, and Encounters

27Jan/100

Unable to jump to row 0 on MySQL result index

I recently found this in the error logs of apache.

PHP Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 1831 in /usr/local/www/domain/script.php on line 97

Looking at line 97, this was the current code snip.

$test = 0;
$rs = mysql_query("SELECT id FROM temp_table WHERE userId = '125366' LIMIT 1");
$test = mysql_result($rs, 0,'id');

The problem with that code is, if you get no results, your still pull results. It should be

$test = 0;
$rs = mysql_query("SELECT id FROM temp_table WHERE userId = '125366' LIMIT 1");
if (mysql_num_rows($res) == 1)
$test = mysql_result($rs, 0,'id');

This way, if we have no results, $rest stays at 0 instead of the userId that we want to return.

Filed under: Errors No Comments