Jump to content

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 />";
}
?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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