我想从表中选择最近的条目,看看该条目是否与用户尝试输入的条目完全相同.如何查询"从最近的'发布'条目中选择*"?
$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'
";
Run Code Online (Sandbox Code Playgroud)
gro*_*gel 10
orderby片段需要在查询结束时出现.所以你要求的查询是这样的:
select * from posting where .... order by date_added desc limit 1;
Run Code Online (Sandbox Code Playgroud)
一次性表单令牌也可以帮助防止重复提交.
| 归档时间: |
|
| 查看次数: |
14374 次 |
| 最近记录: |