Jump to content

Recommended Posts

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/222532-order-by-desc-limit-1-help/
Share on other sites

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.

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.

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.