...

View Full Version : Need Help!! mysql_result() [function.mysql-result]



dunhillx69
01-06-2012, 05:37 AM
hi guys... i need help with this coding... i had this error message while running the php..

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in C:\wamp\www\25122011\files.php on line 160.

And here is the coding from line 156-179:


<?PHP
include("connect.php");
$fnn = $_POST['finoname'];
$query = mysql_query("SELECT * FROM files WHERE fileno = '$fnn' ");
$fno = mysql_result($query,0,0);
$fname = mysql_result($query,0,1);
$floc = mysql_result($query,0,3);
$fres = mysql_result($query,0,5);
$query2 = mysql_query("SELECT * FROM files WHERE filename = '$fnn' ");
$fno2 = mysql_result($query2,0,0);
$fname2 = mysql_result($query2,0,1);
$floc2 = mysql_result($query2,0,3);
$fres2 = mysql_result($query2,0,5);
$idindb = mysql_query("SELECT * FROM files WHERE filename = '$fnn' OR fileno = '$fnn' ");
$isidindb = mysql_num_rows($idindb);

if ($fnn == ''){
echo "<font color='red'>Please make sure the finoname is correct.</font>";
} else
if ($isidindb == 0){
echo "<font color='red'>No record found for that finoname</font>";
}else {
echo"<b><font color='red'> $fno$fno2 - $fname$fname2 - $floc$floc2 - $fres$fres2 </font></b>";}
?>

million thanks in advance...

_Aerospace_Eng_
01-06-2012, 05:46 AM
Your queries are likely failing so do some error checking, change your code to the following and post your results.

<?PHP
include("connect.php");
$fnn = $_POST['finoname'];
$query = mysql_query("SELECT * FROM files WHERE fileno = '$fnn' ") or die(mysql_error().'<br>query');
$fno = mysql_result($query,0,0);
$fname = mysql_result($query,0,1);
$floc = mysql_result($query,0,3);
$fres = mysql_result($query,0,5);
$query2 = mysql_query("SELECT * FROM files WHERE filename = '$fnn' ") or die(mysql_error().'<br>query2';
$fno2 = mysql_result($query2,0,0);
$fname2 = mysql_result($query2,0,1);
$floc2 = mysql_result($query2,0,3);
$fres2 = mysql_result($query2,0,5);
$idindb = mysql_query("SELECT * FROM files WHERE filename = '$fnn' OR fileno = '$fnn' ") or die(mysql_error().'<br>idindb query');
$isidindb = mysql_num_rows($idindb);

if ($fnn == ''){
echo "<font color='red'>Please make sure the finoname is correct.</font>";
} else
if ($isidindb == 0){
echo "<font color='red'>No record found for that finoname</font>";
}else {
echo"<b><font color='red'> $fno$fno2 - $fname$fname2 - $floc$floc2 - $fres$fres2 </font></b>";}
?>

dunhillx69
01-06-2012, 07:16 AM
thanks for your reply... but it seems like it doesn't solve the issue... the error remain the same as follows;

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in C:\wamp\www\25122011\files.php on line 160

Fou-Lu
01-06-2012, 05:20 PM
Not necessarily failing, the above error indicates its more likely that there are simply no results.
You'll need to make use of mysql_num_rows to check if you can actually move to a record before attempting to retrieve it.

I'm a little curious as to why you have three queries to effectively do the same thing. fileno sounds to me like an integer versus the filename of a string. I wouldn't use the OR statement here, since I could have a filename 1 and a fileno 1 if this assumption is correct. This would assume that filename and fileno do not need to correspond, so you could have unintended results.
If fileno is a number, check it as such first:


if (isset($_POST['finoname']))
{
$sProvided = $_POST['finoname'];
$sQry = 'SELECT * FROM files';
if (is_numeric($sProvided))
{
$sQry .= ' WHERE fileno = ' . (int)$sProvided;
}
else
{
$sQry .= ' WHERE filename = \'' . mysql_real_escape_string($sProvided) . '\'';
}

$idindb = mysql_query($sQry) or die(mysql_error());
if (mysql_num_rows($idindb) > 0)
{
list($fno, $fname, $floc, $fres) = mysql_fetch_row($idindb);
}
else
{
print 'no results';
}
}
else
{
print 'nothing to query';
}

_Aerospace_Eng_
01-07-2012, 04:29 AM
thanks for your reply... but it seems like it doesn't solve the issue... the error remain the same as follows;

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in C:\wamp\www\25122011\files.php on line 160

I never said it was going to "solve" the issue. :rolleyes:

We needed to rule out that your queries weren't failing.

Fou-Lu
01-07-2012, 05:26 AM
Also, since aero replied I realized I biffed something too. With my code rather than having a potential of 2 results with a filename and fileno being the same, I now have only the ability to fetch the fileno instead of the filename, which is actually worse IMO.
So in hinds sight, the OR is probably the best choice here, and use a loop to check the results.

Aero's still right when it comes to some sort of error handling, whether it be a die or something more graceful. You should always check that something does exist off of a resource. Fortunately, resources will return false (or null in some situations) if they fail. So using fopen or mysql_query or whatever can be checked with a simple assignment and if if you would like:


if ($qry = mysql_query($sQry))
{
// good, keep going
}
else
{
print 'Oops, something went wrong with site. Please check back later';
}

for example.
Since these are external, you don't want PHP to deal with this itself. This is much like throwing an exception; pass the buck back to the caller to determine how to deal with the failure.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum