Solved

mysql index warning error

Posted on 2011-03-02
12
313 Views
Last Modified: 2012-08-13
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
Comment
Question by:peter_coop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 4

Expert Comment

by:KazooSoft
ID: 35019353
Are you certain that query returns any rows?
0
 

Author Comment

by:peter_coop
ID: 35019740
hi

i have tried echo $result and that produces Resource id #103. what i was expecting to see was a number like 4646.
0
 
LVL 4

Expert Comment

by:KazooSoft
ID: 35019933
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35020098
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
 

Author Comment

by:peter_coop
ID: 35020573
@bportlock

result: This will return 0 rows. thanks

@KazooSoft

it printed nothing at all. thanks
0
 

Author Comment

by:peter_coop
ID: 35020600
@KazooSoft

if i run command through myphpadmin it shows correct data in window. thanks
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35021052
>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
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 35023101
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 35023109
Add ending apostrophe on line 13.  Feel free to add conditional logic instead of the echo on line 23.
0
 

Author Closing Comment

by:peter_coop
ID: 35025979
thanks ray. this helped me visualise the flow of the logic and now i can move forward. thank you
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 35026070
Thanks for the points.  Data visualization is almost always helpful!  Best regards, ~Ray
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question