Jump to content

Recommended Posts

Say i have 10 rows returned from a query... and of them 10 rows i want to currently use... row 7....

 

 

How would i get to echo only row 7 out of the 10 rows there?

 

I tried:

<?php
$Get = mysql_query("SELECT Odds,ObjectID FROM objectfinder WHERE Rareity='Museum' AND
		ObjectID < 2016 AND RecordID > $Found ORDER BY Odds ASC Limit 10") 
	Or die(mysql_error());
$Found = 7;
mysql_data_seek($Get,$Found);
$row = mysql_fetch_assoc($Get);
       Echo $ObjectID;

?>

 

How ever the result i get is this:

 

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 81 is invalid for MySQL result index 40 (or the query data is unbuffered) in C:\xampp\htdocs\musem.php on line 160

 

 

What function do I need?

 

Hope you can help.

Link to comment
https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/
Share on other sites

Heres an example of what im trying to do:

 

Say a query returns 100 rows based on the WHERE Clause set... then say i just want row number 7 to echo the fields on the page..because a staff members wants to look at a particular row ....without knowing the ID or its contents ....how would i do it ?

you need to call out your variable $Found before your query if you're going to use it in your query.

 

your also calling out to echo the variable $ObjectID, but you don't assign that variable any value.

 

and I would think maybe add a COUNT into the query and assign them into an array and return the 7th item of the array.

 

Just a thought.

 

I'd have to go look up how to use COUNT to make that work, but I would start with these corrections:

 

<?php
  $Found = 7; 
  $Get = mysql_query("SELECT Odds,ObjectID FROM objectfinder WHERE Rareity='Museum' AND
         ObjectID < 2016 AND RecordID > $Found ORDER BY Odds ASC Limit 10") 
      Or die(mysql_error());
   $row = mysql_fetch_assoc($Get);
   $ObjectID = $row['ObjectID'];
       echo ($ObjectID);
    ?>

 

Someone with more experience might have a cleaner way to do this, but it's an odd request to want to return a specific line in a query without knowing what the data you're looking for is, or what the resulting data you pull up would be.

All im doing is looking for record IDs between number of $Found (ok that was in the wrong place)..... and less than 2016... and from that returned result say it was:

 

1

2

3

4

5

6

7

8

9

10

 

 

I want to only select row 7 of them 10 rows..... that were selected from the query... =/

Either im misunderstanding you here or you might have misunderstood me still......

 

Say for example:

 

SELECT rows from users with name "Dave"

 

10 rows were returned because 10 rows have the name Dave.. and the user using the system wanted the 7th row in the result.

 

Wouldn't Limit 7 , 1 just give you the first row of the 7 rows returned?

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.