Jump to content

Recommended Posts

I have a form that is populated with information from a mysql table with intentions to edit the copy. When I click the "update" button to update the copy, I get

 

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 32

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 33

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 34

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/sites/site19/eventsEdit.php on line 35

 

Can someone explain why this is happening?

 

Lines 28-36 (the erroring lines are $id to $eventImage)

  <?php
mysql_select_db($database, $Site);
$query = "SELECT * FROM events WHERE eventID = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$id = mysql_result($result,$i,"eventID");
$eventTitle = mysql_result($result,$i,"eventTitle");
$eventInfo = mysql_result($result,$i,"eventInfo");
$eventImage = mysql_result($result,$i,"eventImage");
?>

 

mysql_result() in addition to being the slowest way of fetching information from a result set has the unfortunate problem of generating an error when there are zero rows in the result set.

 

You should use the mysql_num_rows() function to check if there are any rows in the result set before your attempt access the data or you should use one of the mysql_fetch_xxxxxx() functions instead. They simply return a FALSE value when there are zero rows in the result set and don't generate that error. They are also faster because they fetch a whole row at one time.

does $i actually have a value?  based on the errors output I'm guessing not.

 

Personally I don't like querying like this, try this alternative:

 

<?php

mysql_select_db($database, $Site);
$query = "SELECT * FROM events WHERE eventID = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

if(mysql_num_rows($result) > 0) {

$row = mysql_fetch_object($result);

$id = $row->eventID;
$eventTitle = $row->eventTitle;
$eventInfo = $row->eventInfo;
$eventImage = $row->eventImage;

} else {

// Query was empty

}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.