Link to home
Start Free TrialLog in
Avatar of peter_coop
peter_coopFlag for United Kingdom of Great Britain and Northern Ireland

asked on

mysql index warning error

hello

i am seeing this error when i submit data to db and do not know how to correct it.

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 103.

this points to line 40 in the posted code. it is however inserting the data correctly.  i would be grateful if someone could point out how to correct this error.many thanks
<?php 
				function get_btref(){
				$company = $_SESSION['kt_idcom_usr'];
				$sql = 'select btref'
				. ' from boxes'
				. " where customer = '$company'"
				. ' order '
				. ' by id desc'
				. " limit 1";
				$result = mysql_query($sql);
				$btref = mysql_result($result,0,"btref"); <--- LINE 40
				return $btref + 1;} 
?>

Open in new window

Avatar of KazooSoft
KazooSoft
Flag of United Kingdom of Great Britain and Northern Ireland image

Are you certain that query returns any rows?
Avatar of peter_coop

ASKER

hi

i have tried echo $result and that produces Resource id #103. what i was expecting to see was a number like 4646.
Can you run the query in something like phpmyadmin or directly on the server?

Try this instead of echo the "result

print_r(mysql_fetch_assoc($result));
Avatar of Beverley Portlock
After this

$result = mysql_query($sql);


Add this

echo "This will return ".  mysql_num_rows( $result )  ." rows";


and you may as well alter the query to

$result = mysql_query($sql) or die( mysql_error() );

@bportlock

result: This will return 0 rows. thanks

@KazooSoft

it printed nothing at all. thanks
@KazooSoft

if i run command through myphpadmin it shows correct data in window. thanks
>i have tried echo $result and that produces Resource id #103.
means that the query run successfully. does not mean it actually returned rows
the output of mysql_num_rows returning 0 confirms that

>what i was expecting to see was a number like 4646.
means that somehow the query is wrong, or you connect to another database, or it's not the correct SESSION data you get.
print $sql to "see" the query before running it.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Add ending apostrophe on line 13.  Feel free to add conditional logic instead of the echo on line 23.
thanks ray. this helped me visualise the flow of the logic and now i can move forward. thank you
Thanks for the points.  Data visualization is almost always helpful!  Best regards, ~Ray