EchoFool Posted February 23, 2009 Share Posted February 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/ Share on other sites More sharing options...
fenway Posted February 23, 2009 Share Posted February 23, 2009 What are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-769061 Share on other sites More sharing options...
EchoFool Posted February 23, 2009 Author Share Posted February 23, 2009 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-769291 Share on other sites More sharing options...
EchoFool Posted February 23, 2009 Author Share Posted February 23, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-769543 Share on other sites More sharing options...
Alith7 Posted February 23, 2009 Share Posted February 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-769557 Share on other sites More sharing options...
EchoFool Posted February 23, 2009 Author Share Posted February 23, 2009 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... =/ Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-769596 Share on other sites More sharing options...
corbin Posted February 24, 2009 Share Posted February 24, 2009 So why not use LIMIT differently? LIMIT 7, 1 Or, you could probably use mysql_result(). Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-769692 Share on other sites More sharing options...
fenway Posted February 24, 2009 Share Posted February 24, 2009 Which 7? What if there are fewer than 7? Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-770178 Share on other sites More sharing options...
EchoFool Posted February 24, 2009 Author Share Posted February 24, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-770209 Share on other sites More sharing options...
fenway Posted February 25, 2009 Share Posted February 25, 2009 Wouldn't Limit 7 , 1 just give you the first row of the 7 rows returned? Yes, you're right.... you'd need "LIMIT 999999999, 7" to get the 7th -- no support for negative index, unfortunately. But why would you want the 7th? Quote Link to comment https://forums.phpfreaks.com/topic/146451-select-specific-row-from-results/#findComment-770816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.