本文介绍了如何选择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中的最新条目?
发布评论