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
https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/
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.

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?)

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;

  }}

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

 

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.

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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.