title: PHP/MySQL query for row index (not id) in a table
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3126972/mysql-row-number">MySql Row Number?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm using PHP 5 and mysqli. I have a table of chapters with columns 'id' and 'name'. Is there a simple and efficient way to query to check what index a specified row is located at? For example, lets say the records in my 'chapters' table are:</p>
  
  <hr>
  
  <p>id | name</p>
  
  <p>1 | Hello</p>
  
  <p>4 | World</p>
  
  <p>5 | How are you?</p>
  
  <hr>
  
  <p>And lets say I want to find out where "How are you?" is. The desired result would be index 3 (since it is the third row in the table sorted by id ascending).</p>
  
  <p>The only solution I've come up with is to query for all of them, and then in PHP loop through and find where $row["id"] == 5 and figuring out what iteration it is in the loop. Is there a more efficient way to do this?</p>