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

编程入门 行业动态 更新时间:2024-10-24 06:26:22
本文介绍了如何选择mysql中的最新条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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'"?

$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 "<br>"; $linkposting_id=$row['posting_id']; echo "See the <a href='ad.php?posting_id=$linkposting_id'>Ad</a>"; } 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' ";

推荐答案

orderby件需要出现在查询的末尾.因此,您要查询的是这样的:

The orderby piece needs to come at the end of your query. So the query you're asking for is something like this:

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

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

Single-use form tokens can help prevent duplicate submissions, too.

更多推荐

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

本文发布于:2023-10-14 21:53:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492319.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   如何选择   最新   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!