Page 1 of 1

Warning: mysql_result() [function.mysql-result]: Unable to j

Posted: Tue Jan 04, 2011 6:43 am
by batowiise
Hi all,

I have this error message for about 7 days now (Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 8 in C:\xampp\htdocs\RAFIS\welcome.php on line 20), I have searched the on the net but not getting any clue yet.

My code is as follow:

Code: Select all

session_start();
$username = $_SESSION['username']; 

require_once("admin/db.php");
$result = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
$results = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
$resultes = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
$rs = mysql_query("SELECT * FROM generalclaims WHERE systemapprovallist='FIRST'") or die(mysql_error());
$rs1 = mysql_query("SELECT * FROM generalclaims WHERE systemapprovallist='SECOND'") or die(mysql_error());
$rs2 = mysql_query("SELECT * FROM generalclaims WHERE systemapprovallist='THIRD'") or die(mysql_error());
$rsdepartment = mysql_query("SELECT * FROM generalclaims") or die(mysql_error());

$pettycashapprover = mysql_result($result,0,'pettycashapprover');
$approvallevel = mysql_result($results,0,'approvallevel');
$userdepartment = mysql_result($resultes,0,'department');
$systemapprovallist = mysql_result($rs,0,'systemapprovallist');
$systemapprovallist1 = mysql_result($rs1,0,'systemapprovallist');
$systemapprovallist2 = mysql_result($rs2,0,'systemapprovallist');
$gendepartment = mysql_result($rsdepartment,0,'department');

if($_SESSION['username'] == $username && $pettycashapprover == 'YES' && $approvallevel == 'FIRST' && $systemapprovallist == 'FIRST' && $userdepartment == 'FINANCE' &&    $gendepartment == 'FINANCE')
{
	echo"<script>alert('Issues Pending for your approval.');</script>";
}

elseif($_SESSION['username'] == $username && $pettycashapprover == 'YES' && $approvallevel == 'SECOND' && $systemapprovallist1 == 'SECOND')
{
	echo"<script>alert('Issues Pending for SECOND your approval.');</script>";
}

elseif($_SESSION['username'] == $username && $pettycashapprover == 'YES' && $approvallevel == 'THIRD' && $systemapprovallist2 == 'THIRD')
{
	echo"<script>alert('Issues Pending for THIRD your approval.');</script>";
}

Is it a problem with mysql_result(). I was informed to use mysql_fetch_assoc() but I am confused about its usages especially to achieve my objective.

Your help needed please.

Regards,

Re: Warning: mysql_result() [function.mysql-result]: Unable

Posted: Tue Jan 04, 2011 7:54 am
by Neilos
Which line is line 20? is it;

Code: Select all

$gendepartment = mysql_result($rsdepartment,0,'department');
Line 20 of your code is a blank line, I assume this is because you simply haven't posted the <?php ?> tags.

I use mysql_fetch_array($result, MYSQL_ASSOC), I think that the mysql_fetch_assoc() is quicker (ie performance) but I always used mysql_fetch_array() and I think that there is some benefit.

I think that this error is given when mysql_result() acts on no rows. If this is the case you could use an if clause with mysql_num_rows() to determine if there are any results. Or if you don't want loads of if statements, just make sure that you always get returned something.

Is this perhaps the problem?
batowiise wrote: Is it a problem with mysql_result()
Well the error is being generated from the mysql_result() function but I think that the problem more likely lies in the query that the function acts on. Or a combination of the two.

It's not really an error with your code as the syntax is good (I haven't checked but it looks ok). The error, I think, is in your implementation. It could be a typo however, have you checked all the names from your code to the database?

Re: Warning: mysql_result() [function.mysql-result]: Unable

Posted: Tue Jan 04, 2011 8:07 am
by batowiise
My line 20 is

Code: Select all

$systemapprovallist1 = mysql_result($rs1,0,'systemapprovallist');
What happens is the values of systemapprovallist keeps changing. How do i use the mysql_fetch_assoc() to achieve the same thing as mysql_result().

Any sample code from your end will be appreciated.

Regards.

Re: Warning: mysql_result() [function.mysql-result]: Unable

Posted: Tue Jan 04, 2011 8:23 am
by Neilos
There is lots of information about the mysql_fetch_assoc() function here;

http://php.net/manual/en/function.mysql-fetch-assoc.php

Example code, lifted from the above manual;

Code: Select all

$sql = "SELECT id as userid, fullname, userstatus 
        FROM   sometable
        WHERE  userstatus = 1";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}
Without knowing the structure of your tables it is difficult to see what exactly it is that you are trying to pull from the database with the code you have.

$rs1 returns a query with one or many rows? It looks like it would be many rows as there is only three options and there has got to be more than three data entries?