-1

Get this error on a social network university project i'm creating.

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in /customers/2/f/b/somesrandomsite.com/httpd.www/rnfunctions.php on line 63

Here's the PHP code in question...

function showProfile($user) {

    $UserID = mysql_result(mysql_query("SELECT `user_id` FROM `rnprofiles` WHERE `user` = '$user'"), 0) or die(mysql_error());        
    $Query = mysql_query("SELECT * FROM `images` WHERE `user_id` = '$UserID'") or die(mysql_error());
    while ($ImageData = mysql_fetch_assoc($Query)) {

        echo '<p><a title="'.$user.'" class="fancybox" data-fancybox-group="gallery" href="'.$ImageData['location'].'"><img src="'.$ImageData['location'].'" border="" align="left" height="150" width="150" alt=""/></a></p>';// Display each image belonging to the user
    }

    $result = queryMysql("SELECT * FROM rnprofiles WHERE user='$user'") or die(mysql_error());

    if (mysql_num_rows($result))
    {
        $row = mysql_fetch_row($result);
        echo stripslashes($row[1]) . "<br clear=left /><br />";
    }

}

If anyone had any thoughts it'd be a great help.

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
BenRV
  • 45
  • 1
  • 2
  • 10
  • 1
    Never nest `mysql_query()` inside any `mysql_result()` or `mysql_fetch_*()` call. If the query fails or returns no rows ( as is your case), which is not an error condition, the subsequent outer call will fail with error. – Michael Berkowski Apr 24 '13 at 01:53
  • I'm not familiar with that particular error message, but it appears to me there are no results in the result set. Never assume what a `mysql_query` call returns! It may be `false`, it may be an empty set, it may be anything. Do some error handling! – deceze Apr 24 '13 at 01:53
  • Verify your first query up there. Most likely, the variable `$user` does not contain what you expect it to contain... – Michael Berkowski Apr 24 '13 at 01:53
  • 2
    Welcome to Stack Overflow! [Please, don't use `mysql_*` functions](http://stackoverflow.com/q/12859942/1190388) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the red box? Learn about prepared statements instead, and use [tag:PDO] or [tag:MySQLi]. – hjpotter92 Apr 24 '13 at 02:30
  • @hjpotter92 man you guys get a lot of use out of that factoid... – sevenseacat Apr 24 '13 at 04:23
  • @sevenseacat http://stackapps.com/questions/2116/autoreviewcomments-pro-forma-comments-for-se – hjpotter92 Apr 24 '13 at 04:24
  • @hjpotter92 I figured it was something like that :p Nice. – sevenseacat Apr 24 '13 at 04:34

2 Answers2

1

whenever you will use $row = mysql_fetch_row($result);

because $result only stores the resource id. So each time you will iterate it in loop it goes to another row if exists.

To get all data you have to use while loop like below

while($row = mysql_fetch_row($result))
{
  //do your operation
}
BlitZ
  • 12,038
  • 3
  • 49
  • 68
1

Calls to mysql_result() should not be mixed with calls to other functions that deal with the result set.

refer to here

So, change

$UserID = mysql_result(mysql_query("SELECT `user_id` FROM `rnprofiles` WHERE `user` = '$user'"), 0) or die(mysql_error());

to this

$result=mysql_query("SELECT `user_id` FROM `rnprofiles` WHERE `user` = '$user'") or die(mysql_error());
$UserID = mysql_result($result,0);

Also, there is a syntax error. change queryMysql to mysql_query

Amir
  • 4,089
  • 4
  • 16
  • 28
  • When i apply these changes this error appears as there is an extra bracket after the second parameter. Parse error: syntax error, unexpected ',' in /customers/2/f/b/somesite.com/httpd.www/rnfunctions.php on line 64 – BenRV Apr 24 '13 at 12:46
  • sorry...i edited my answer – Amir Apr 24 '13 at 12:55
  • Still get this error ´Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5´ – BenRV Apr 24 '13 at 13:01
  • perhaps there is no record in `$result`. are you sure your query returns something? try put real user instead of `$user` to know if your query works. – Amir Apr 24 '13 at 13:07
  • `Unable to jump to row 0 ...` means your query does not put any record. try to use `like`. it should be `WHERE user LIKE '%".$user."%'"` – Amir Apr 24 '13 at 13:28
  • that also had no effect – BenRV Apr 24 '13 at 13:49