Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL- Unable to jump to row 0 on MySQL result index

I have got an old site that has recently been displaying an error which is weird as its been untouched for some time. I get the following:

Unable to jump to row 0 on MySQL result index 8

What is the cause of this and how should I fix it?

It is a PHP/MySQL site.

like image 743
Zabs Avatar asked Dec 01 '11 13:12

Zabs


2 Answers

If I remember correctly, this error typically stems from a code segment like the following:

// You probably have some code similar to this
$var = mysql_result( $result, 0, 'column_name');

Where either the query fails or the column doesn't exist. Check that $result is a valid MySQL resource to make sure that the SQL is valid, then make sure you're actually getting results from the database before trying to call mysql_result.

Or, better yet, using mysql_fetch_array instead of manually fetching every column value (if you have multiple columns returned from the query).

like image 140
nickb Avatar answered Nov 14 '22 23:11

nickb


Try analysing the result before fetching it. If result is empty, skip fetching.

$result = mysql_query("SELECT * FROM table1");
if (!$result || !mysql_num_rows($result)) {
    die('Empty set.');
}
while ($row = mysql_fetch_array($result)) {
    // Your code here
}
like image 35
Minras Avatar answered Nov 15 '22 01:11

Minras