SQL Error - Anyone know what I have done wrong?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
trvo
Forum Newbie
Posts: 7
Joined: Tue Feb 03, 2004 5:34 pm

SQL Error - Anyone know what I have done wrong?

Post by trvo »

Hi guys,

I have been trying to figure this out but can't. I keep getting this error in my mysql_result line:

Warning: Unable to jump to row 0 on MySQL result index 3 in c:\program files\easyphp\www\cmr\list.php on line 42

Here is the code:

Code: Select all

while($x < $count) {
$x++;
$r = @mysql_query("SELECT * FROM logbook WHERE 'id'=$x"); 
if (!$r) die ('Query for count failed: '.mysql_error()); 
$date=mysql_result($r,0,"date");
There are more lines following like the $date=mysql_result($r,0,"date");

Does anyone have an idea of what I am doing wrong here?

Thanks and Kind Regards - Trvo
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

I would rearrange the code as follows to add a bunch of debugging to find out where things are going wrong:

Code: Select all

while ($x < $count) {
    $x++;
     // note that you shouldn't have single quotes around the field name
     // and that naming the fields you want to retrieve can make life easier
    // in the long run
    $sql = "SELECT date, field2, field3, field4 FROM logbook WHERE id=$x";
     // for debugging echo out the SQL query:
     echo '<p>'.$sql.'</p>';

    @$result = mysql_query or die(mysql_error().'<p>'.$sql.'</p>');
     
     // for debugging check out how many rows have been returned:
     echo '<p>'.mysql_num_rows($result).' rows returned</p>';

      // get the row returned if there is one
     $row = mysql_fetch_assoc($result);
     
     // debugging, echo the result from the database:
     echo '<pre>';
     print_r($row);
     echo '</pre>';
}
Mac
trvo
Forum Newbie
Posts: 7
Joined: Tue Feb 03, 2004 5:34 pm

Post by trvo »

Hi,

I have done what you said. It now works, thanks a lot for your kind help.

Kind Regards - trvo
Post Reply