php – 如何在mysql中选择最新的条目?

前端之家收集整理的这篇文章主要介绍了php – 如何在mysql中选择最新的条目?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想从表中选择最近的条目,看看该条目是否与用户尝试输入的条目完全相同.如何查询“从最近的’发布’条目中选择*”?

    $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)>0)
 {
  echo "You already posted this ad. Most likely caused by refreshing too many times.";
  echo "
最佳答案
orderby片段需要在查询结束时出现.所以你要求的查询是这样的:

select * from posting where .... order by date_added desc limit 1;

一次性表单令牌也可以帮助防止重复提交.

猜你在找的MySQL相关文章