Jump to content

Unable to jump to row 0 on MySQL result


Deanznet

Recommended Posts

Okay, What we have here, is that the script selects a email and password from the database and when it dose it puts used to 0

 

and then if i vist the page again its suppose to select another one and then set it to 0.

 

But i get this error below if one of the is set to  0 and the script wont use the ones that are not set to 0

 

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 2 in index.php on line 16

 

 

    mysql_select_db($database);
    $query=mysql_query("select count(*) from where used=0");
    $count=mysql_result($query,0);
    $i=rand(1,$count);
    //echo $i;
    $query_email=mysql_query("select email from logins where userID='$i' and used=0");
    $email=mysql_result($query_email,0);

Link to comment
https://forums.phpfreaks.com/topic/184652-unable-to-jump-to-row-0-on-mysql-result/
Share on other sites

The error means that there are zero rows in your result set. mysql_result has the misfortune of being the only way to fetch data from a result set that generates an error when there are no rows in the result set. The error is either because your query failed to execute at all (you should test that value that mysql_query returns before you blindly attempt to access the result resource) or simply because the WHERE clause did not match any rows (you should use mysql_num_rows() to find out if there are any rows in the result set before you attempt to fetch any data from the result set.)

Here is really the minimum logic that should be used when executing a query -

 

<?php
$query = " ... "; // your query in a string variable (makes error reporting easier because you can log or display the actual query)
// execute the query and check for success or failure
if($result = mysql_query($query)){
// the query executed without any errors and returned a result resource or a TRUE value
// check if any rows were returned by the query (SELECT queries)
if(mysql_num_rows($result)){
	// the result set contains one or more rows
	// process the row(s) in the result set here...
} else {
	// no rows were matched, output a helpful user error message
	echo "The query did not match any rows in the database<br />";
}
} else {
// the query failed and returned an FALSE value
// do your application level error reporting here...

// output a helpful user error message
echo "The query could not be executed at this time due to an error<br />";
}
?>

 

 

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.