title: Count number of rows until given value in MySQL table
body: <p>I've searched for quite a while for an answer to this with no luck.  Sorry if this is answered somewhere I couldn't find.</p>
  
  <p>I basically have a queue in a MySQL table and I need to tell people what number they are in the queue using PHP.</p>
  
  <p>Right now, I've got this, but all it does is count the number of rows in the table:</p>
  
  <pre><code>$rowquery = "SELECT * FROM restaurant_guests ORDER BY ID UNTIL";
  if ($stmt = $mysqli2-&gt;prepare($rowquery)) {
  
  /* execute query */
  $stmt-&gt;execute();
  
  /* store result */
  $stmt-&gt;store_result();
  
  printf("%d", $stmt-&gt;num_rows - 1);
  
  /* close statement */
  $stmt-&gt;close();
  }               
  </code></pre>
  
  <p>Can someone please help point me in the right direction?  Thank you so much in advance! :)</p>