Jump to content

help with mysql_result


elotherguy

Recommended Posts

Hi, i know that this is a mysql question but i was hoping you guys would be able to help me!  This is the error I get:

 

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 38 in /home/caritasd/public_html/am/libs/MySQL.class.php on line 118

 

 

  public function result($sql){

    if(!($res = mysql_query($sql, $this->link)))

      trigger_error("Error: Invalid query -> ".$sql."<br />MySQL said: ".mysql_error()."<br /><br />");

117    else

118      if(($return = mysql_result($res,0)))

119        return $return;

      else

        return false;

  }

Link to comment
Share on other sites

mysql_result, in addition to being the slowest way to get data from a result set is the only function that generates an error message when there are zero rows in the result set. You either need to test if there are any rows in the result set before using mysql_result or you need to use one of the mysql_fetch_xxxxx functions instead.

Link to comment
Share on other sites

mysql_result, in addition to being the slowest way to get data from a result set is the only function that generates an error message when there are zero rows in the result set. You either need to test if there are any rows in the result set before using mysql_result or you need to use one of the mysql_fetch_xxxxx functions instead.

 

Shouldn't it be faster than mysql_fetch_xxxxx when returning a scalar result? (i.e a single column with a single row?)

Link to comment
Share on other sites

Just add a condition like:

 

  public function result($sql){

    if(!($res = mysql_query($sql, $this->link)))

      trigger_error("Error: Invalid query -> ".$sql."

MySQL said: ".mysql_error()."

 

");

    else

 

$numrows = mysql_numrows($res);

 

if ($numrows == 0){

 

trigger_error("Error: Query -> ".$sql." returned 0 results.");

 

}else{

 

      if(($return = mysql_result($res,0)))

        return $return;

      else

        return false;

  }}

Link to comment
Share on other sites

when i do that, this is the new error:

 

Notice: Error: Query -> SELECT `name` FROM `images` WHERE listing_id='ceebe6f4-ea9d-4757-8a1c-7bd08daf5ac5' ORDER BY `order` ASC LIMIT 1 returned 0 results. in /home/caritasd/public_html/am/libs/MySQL.class.php on line 122

 

Link to comment
Share on other sites

Shouldn't it be faster than mysql_fetch_xxxxx when returning a scalar result? (i.e a single column with a single row?)

mysql_result() performs a data seek followed by a data read. The mysql_fetch_xxxxx functions just do a read at the current position.
Link to comment
Share on other sites

ok...one last question :)  so i'm trying to get information to be included in a contact email.  i.e. person's name/email based on when they registered...  however it doesn't inlcude it when i send the email.  Is this because of the previous error???

Link to comment
Share on other sites

Preventing that error from displaying does not change the fact that your query did not match any data in your database. You need to examine the data in your database and examine the query statement and determine why it did not match anything.

 

Your code should also not be continuing and sending an email where the query fails to find and return a matching row from your database (good programming practices.)

Link to comment
Share on other sites

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.