ananaz Posted December 23, 2010 Share Posted December 23, 2010 Hello people. I have a field named id (INT NOT NULL auto_increment) and i want to retrieve numbers from it. But i want to retrieve numbers after how big they are, not just the biggest. For example I want to retrieve the 14th biggest id in the rows. This is my script how to get biggest. Help me please xD <?php $con = mysql_connect("localhost","*****","*********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("********", $con); $result = mysql_query("SELECT id FROM stuff ORDER BY id desc limit 1;"); $stor = $result[0]; echo $stor; mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Maq Posted December 23, 2010 Share Posted December 23, 2010 I'm lost. Can you provide an example? Quote Link to comment Share on other sites More sharing options...
ananaz Posted December 23, 2010 Author Share Posted December 23, 2010 Ok if this is the tables Table id name age 3 ananaz 21 2 karl 12 1 chuck norris 50 I want to be able to pick out the for example second biggest id in this case is 2. Table2 id name age 4 newbie 6 3 ananaz 21 2 karl 12 1 chuck norris 50 and in this case i want it to retrieve 3. Quote Link to comment Share on other sites More sharing options...
Maq Posted December 23, 2010 Share Posted December 23, 2010 You have the correct query, you just need to alter the value after limit. Relating to your first example you would use: ORDER BY id DESC LIMIT 1,1 This means, after you order by 'id', it will go to the first row and select the first one after it. Quote Link to comment Share on other sites More sharing options...
ananaz Posted December 23, 2010 Author Share Posted December 23, 2010 thank you it i got it to work now Quote Link to comment Share on other sites More sharing options...
Maq Posted December 24, 2010 Share Posted December 24, 2010 thank you it i got it to work now Good. Make sure to mark your threads solved, thx. Quote Link to comment 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.