Solved

mysql index warning error

Posted on 2011-03-02
12
309 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 4

Expert Comment

by:KazooSoft
ID: 35019935
0
 
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 142

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 109

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 109

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 109

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
send post values 7 26
SQL SELECT query help 7 41
What's wrong with this T-SQL Foreign Key? 7 45
Mysql Left Join Case 10 55
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

777 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