• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

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

0
peter_coop
Asked:
peter_coop
  • 4
  • 3
  • 3
  • +2
1 Solution
 
KazooSoftCommented:
Are you certain that query returns any rows?
0
 
peter_coopAuthor Commented:
hi

i have tried echo $result and that produces Resource id #103. what i was expecting to see was a number like 4646.
0
 
KazooSoftCommented:
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));
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
Beverley PortlockCommented:
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() );

0
 
peter_coopAuthor Commented:
@bportlock

result: This will return 0 rows. thanks

@KazooSoft

it printed nothing at all. thanks
0
 
peter_coopAuthor Commented:
@KazooSoft

if i run command through myphpadmin it shows correct data in window. thanks
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>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.
0
 
Ray PaseurCommented:
This is obviously untested - I do not have your data base, but I think it might give you what you want, or at least the diagnostic information you need.
<?php // RAY_temp_petercoop.php
error_reporting(E_ALL);


// MODIFIED FROM THE ORIGINAL POST AT EE
function get_btref()
{
    $company = $_SESSION['kt_idcom_usr'];
    $sql = 'SELECT btref'
    . ' FROM boxes'
    . " WHERE customer = '$company'"
    . ' ORDER BY id DESC'
    . ' LIMIT 1
    ;
    $res = mysql_query($sql);
    if (!$res)
    {
        echo "<br/>FAIL: $sql<br/>";
        die( mysql_error() );
    }
    
    $num = mysql_num_rows($res);
    echo "<br/>QUERY FOUND $num ROWS";
    
    $row = mysql_fetch_assoc($res);
    $btr = $row["btref"];
    return $btr + 1;
}

Open in new window

0
 
Ray PaseurCommented:
Add ending apostrophe on line 13.  Feel free to add conditional logic instead of the echo on line 23.
0
 
peter_coopAuthor Commented:
thanks ray. this helped me visualise the flow of the logic and now i can move forward. thank you
0
 
Ray PaseurCommented:
Thanks for the points.  Data visualization is almost always helpful!  Best regards, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now