title: How do I select the most recent entry in mysql?
body: <p>i want to select the most recent entry from a table and see if that entry is exactly the same as the one the user is trying to enter. How do I do a query to "select * from the most recent entry of 'posting'"?</p>
  
  <pre><code>    $query="Select * FROM 
          //confused here 
   (SELECT * FROM posting ORDER BY date_added DESC)
   WHERE user_id='{$_SESSION['user_id']}'
   AND title='$title'
   AND price='$price'
   AND city='$city'
   AND state='$state'
   AND detail='$detail'
   ";
  
   $data = mysqli_query($dbc, $query);
   $row = mysqli_fetch_array($data);
   if(mysqli_num_rows($data)&gt;0)
   {
    echo "You already posted this ad. Most likely caused by refreshing too many times.";
    echo "&lt;br&gt;";
    $linkposting_id=$row['posting_id'];
    echo "See the &lt;a href='ad.php?posting_id=$linkposting_id'&gt;Ad&lt;/a&gt;";
   }
   else
   {
          ...insert into the dbc
          }
  
  //would this query work? or how do i use it to select the last ID in the table 'posting'?
      $query="SELECT LAST_INSERT_ID(posting)
       WHERE user_id='{$_SESSION['user_id']}'
       AND title='$title'
       AND price='$price'
       AND city='$city'
       AND state='$state'
       AND detail='$detail'
       ";
  </code></pre>