peter_coop
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
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;}
?>
Are you certain that query returns any rows?
ASKER
hi
i have tried echo $result and that produces Resource id #103. what i was expecting to see was a number like 4646.
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));
Try this instead of echo the "result
print_r(mysql_fetch_assoc(
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() );
$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() );
ASKER
@bportlock
result: This will return 0 rows. thanks
@KazooSoft
it printed nothing at all. thanks
result: This will return 0 rows. thanks
@KazooSoft
it printed nothing at all. thanks
ASKER
@KazooSoft
if i run command through myphpadmin it shows correct data in window. thanks
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Add ending apostrophe on line 13. Feel free to add conditional logic instead of the echo on line 23.
ASKER
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