PDA

View Full Version : Problem "mysql_result(): Unable to jump to row 0"



Joefunkx
10-12-2007, 02:35 PM
Hello,
I am using the following code, and i get an error on the last statement (last line). The error only shows up for the entries that don't exist in the 815SF_attachments table.

Error is -
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 16 in ...index.php on line 25

Any ideas? It's probably something stupid that I'm overlooking.




$select = "SELECT ID_MEMBER FROM 815SF_themes WHERE variable = 'cp1' ORDER BY ID_MEMBER";
$query = mysql_query($select)or die(mysql_error());

while($list = mysql_fetch_object($query))
{
$id = $list->ID_MEMBER;


$sql = "SELECT value FROM 815SF_themes WHERE ID_MEMBER = " . $id . " AND variable = 'cp1'";
$res = mysql_query($sql);
$flname = mysql_result($res, 0);

$sql = "SELECT filename FROM 815SF_attachments WHERE ID_MEMBER = " . $id;
$res = mysql_query($sql);
$avatar = mysql_result($res, 0);

boogyman
10-12-2007, 02:57 PM
i am not sure if this is causing the error or not, but you forgot to put ASC or DESC on the order by..

also in your bottom two queries. This isnt the error that was given, but if you dont encapsulate the ID_MEMBER in quotes, sometimes its read as a column and not a value

$sql = "SELECT value FROM 815SF_themes WHERE ID_MEMBER = '" . $id . "' AND variable = 'cp1'";
...
$sql = "SELECT filename FROM 815SF_attachments WHERE ID_MEMBER = '" . $id ."'";

Joefunkx
10-12-2007, 03:14 PM
Thank you for the corrections.. However, the problem still exists. It has something to do with the fact that it is looping through the tables looking for entries based on MEMBER_ID, and some of the MEMBER_ID's DON'T have an entry in the 815SF_attachments table, and it doesnt know how to fall out without giving the error

djr33
10-12-2007, 05:53 PM
Use @ to suppress errors and an if to see if it works.

Usually, mysql results return multiple rows. When doing this, a while statement is used:
while ($row = mysql_fetch_array($result)) { //do stuff; }

That will go through //do stuff; for the number of rows present in $result, whether that is 10, 5, 1, or even 0*.
(*I think this might give an error, but I don't remember that being the case.)

In your case, it seems you will never want more than one result returned, even if more than one matches exist in the database, so I suggest the same idea, but with an if statement.

You can do this simply by:
if ($row=@mysql_fetch_assoc($result)) { //do stuff; }
And, just in the case a row doesn't exist:
else { echo "sorry, no record exists, etc."; }

As for a MEMBER_ID not existing, that is entirely a fault of the database setup and will not be fixed by any programming/functions. MySQL's use is finite-- you must determine a reliable method for finding the desired data sets-- no way around that.

Joefunkx
10-12-2007, 06:33 PM
Thanks.. the @ was all that I needed. it is intentional that some of the member id's are not on that table.. so all i needed was for it to ignore the fact that they weren't there.. Thanks a lot!!!

djr33
10-12-2007, 10:00 PM
No problem.

Also, note that @ doesn't change the meaning of a function. It will still be true or false, but the @ simply suppresses all errors. So you can still use if (@function()), and that won't change the result, but just not display an error.

mantasmatusevicius
02-07-2013, 03:21 PM
Also you could use this instead of @
if ($variable == null) {
echo "id not exsist"

traq
02-07-2013, 03:25 PM
mantasmatusevicius:

Please check the dates before replying to threads.
The last post to this thread was over five years ago, and the original poster had already found and accepted a solution.

(In addition, if( $variable == null ) won't help with the stated goal: handling the problem while suppressing the error.)

I'm closing this thread. If you (or anyone) has similar questions, please start a new thread.