Jump to content

Unable to jump error


jcg31

Recommended Posts

I am getting an "Unable to jump to row 155 on MySQL result index 4 in C:\wamp\www\Inventory.php on line 64" . 

 

This code is just test code to try and isolate this " unable to jump" issue that I am having with a bigger project

 

In the test code I first tried iterating through the recordset (see code below) which worked without issue, providing the output I would have expected and wanted (including category_id 155).  The category_id is what I am incrementing, so the test verified that the proper id was being passed and that the proper category_label and category_id was being returned.

 

I then tried accessing the category_label using

 <?php echo mysql_result($Recordset1, 155, 2); ?>    (line 64 in the code)

And it threw the error.

 

Any help would be appreciated.

 

Thanks,

Jim

mysql_select_db($database_Inventoryserver, $Inventoryserver);
$query_Recordset1 = "SELECT * FROM category";
$Recordset1 = mysql_query($query_Recordset1, $Inventoryserver) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_Inventoryserver, $Inventoryserver);
$query_Recordset2 = "SELECT * FROM tasks ";
$Recordset2 = mysql_query($query_Recordset2, $Inventoryserver) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
</head>
</head>
<body>
<?php echo mysql_result($Recordset1, 155, 2); ?>
<table width="900" border="1">
  <?php $i=0;
  do { ?>
    <tr>
      <td><?php echo $row_Recordset1['category_label']; ?></td>
      <td><?php echo mysql_result($Recordset1, $i, 2); ?></td>
      <td><?php echo $row_Recordset1['category_id']; ?></td>
    </tr>
    <?php $i++ ?>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>

Link to comment
Share on other sites

you should not be trying to access a specific row number in a result set, because it might not exist (your current error, rows start at zero) and there's no guarantee that any row number will always be the data you expect (deleting rows from a table and not using any ORDER BY in your query will result in different data being in any row number in a result set.)

 

 

your database loop code, wherever you learned it, is inefficient for three reasons -

 

1) mysql_result() is the slowest way of accessing data because it performs a dataseek followed by a read operation,

 

2) you are already fetching the row into a variable, using mysql_result() on top of that isn't necessary. just use the fetched data.

 

3) using a do/while loop takes more code because you must pre-fetch the first row from the result set and you must also add more logic to test if there are any rows at all to avoid errors when accessing non-existent data.

 

you need to (always) use a while(){} loop to iterate over multiple rows from a query -

$query = " your query statement here ...";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
    code that uses the fetched data in $row ..
}

i can guarantee that this method won't ever attempt to access rows that don't exist in the result set. it will loop over only the rows that do exist, even if there are zero rows in the result set (in which case it will skip over the loop.)

Link to comment
Share on other sites

as a continuation of the above replay, there's another (good) reason to NOT use mysql_result() at all. the mysql_ database library is depreciated in php5.5 and should no longer be used and there's no equivalent for the mysql_result() statement in the the mysqli or PDO database libraries that are the replacement for the mysql_ library.

Link to comment
Share on other sites

Thanks Mac_gyver.

 

Learned (learning) from forums like this one, bunches of views on how to do things, I apparantly picked the wrong one.

My iterating through the recordset was just for the purpose of testing my real need (but good to get your input on that).

My real question is how to retrieve a particular row in the recordset? Got my current approach from http://stackoverflow.com/questions/6782615/display-specific-line-or-record-of-a-recordset.

 

So, if Recordset1=

Book1  Author1  Cost1  Remainder1

Book2  Author2  Cost2  Remainder2

Book3  Author3  Cost3  Remainder3

Book4  Author4  Cost4  Remainder4

 

What is the best way to retreive  Cost3?

 

Thanks,

Jim

Link to comment
Share on other sites

i had actually typed a line, but removed it before posting the reply above - if you are trying to retrieve a specific row from a database table, you would retrieve that row using its id or using some other identifying means.

 

how do you know you want to retrieve the row that has the Cost3 value in it? what input does your code have that determines what row and what column you want to find?

Link to comment
Share on other sites

i had actually typed a line, but removed it before posting the reply above - if you are trying to retrieve a specific row from a database table, you would retrieve that row using its id or using some other identifying means.

 

how do you know you want to retrieve the row that has the Cost3 value in it? what input does your code have that determines what row and what column you want to find?

 

Recordset2 comes from the tasks table that contains tasks associated with a particular category of books and marketing of same. Recordset1 has the details of each category.  Both tables have category_id as a field.

 

The application takes the contents of Recordset2 and presents the tasks contained within in table form using a repeater; the category_id is included in a hidden field.  I want the user to be able to hover over a particular task and have a tooltip come up that provides the detail of that category from Recordset1 using the category_id in the hidden field.

Edited by jcg31
Link to comment
Share on other sites

if you are getting the data for the tool tip display using ajax, you would submit the category_id value and use it in a WHERE clause in the query. if you are producing all the tool tips and outputting the information all when the page is requested, you would use a JOIN query to get the relevant data you need from both tables at one time.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.