elotherguy Posted August 1, 2008 Share Posted August 1, 2008 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; } Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/ Share on other sites More sharing options...
ShaunO Posted August 1, 2008 Share Posted August 1, 2008 Looks like your query isn't returning any rows. Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605164 Share on other sites More sharing options...
elotherguy Posted August 1, 2008 Author Share Posted August 1, 2008 know how i can get it to return a row? Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605165 Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2008 Share Posted August 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605166 Share on other sites More sharing options...
elotherguy Posted August 1, 2008 Author Share Posted August 1, 2008 is the mysql_fetch_xx... functions pretty much interchangable? sorry i'm very very new to this and am learning as fast as i can. Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605169 Share on other sites More sharing options...
ShaunO Posted August 1, 2008 Share Posted August 1, 2008 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?) Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605170 Share on other sites More sharing options...
Andy-H Posted August 1, 2008 Share Posted August 1, 2008 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; }} Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605175 Share on other sites More sharing options...
elotherguy Posted August 1, 2008 Author Share Posted August 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605180 Share on other sites More sharing options...
ShaunO Posted August 1, 2008 Share Posted August 1, 2008 What a pain in the ass that mysql_result throws a warning when it fails, considering it sets the value to false. Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605181 Share on other sites More sharing options...
elotherguy Posted August 1, 2008 Author Share Posted August 1, 2008 is there anyway to hide the errors?? Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605183 Share on other sites More sharing options...
DarkWater Posted August 1, 2008 Share Posted August 1, 2008 Remove this line: trigger_error("Error: Query -> ".$sql." returned 0 results."); >_> Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605184 Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2008 Share Posted August 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605187 Share on other sites More sharing options...
Andy-H Posted August 1, 2008 Share Posted August 1, 2008 oops lol Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605189 Share on other sites More sharing options...
elotherguy Posted August 1, 2008 Author Share Posted August 1, 2008 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??? Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605204 Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2008 Share Posted August 1, 2008 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.) Quote Link to comment https://forums.phpfreaks.com/topic/117658-help-with-mysql_result/#findComment-605209 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.