我想在插入之前选择前x行,比如10行。如果插入前没有行,则只返回已插入的行。
插入之后,我可以使用mysql_insert_id()获得id;
是选择插入前的前10行的一种智能方法。
这必须适用于间隔0或10内的任何数字。因此,假设它们在插入之前是7行,那么它只返回8行。
我在考虑像这样使用极限
$insertid = mysql_insert_id()
$postid = 200
Select a, b, c from mytable where a = '$postid' limit $insertid 10 order by b但这不像我想的那样。
发布于 2013-10-30 17:01:51
Select a, b, c from mytable where primary_key_col < '$insertid' and a = 200
ORDER BY primary_key_col DESC LIMIT 10发布于 2013-10-30 17:07:01
您可以在以下之间使用:
Select a, b, c from mytable where a BETWEEN $postid - 10 AND $postid (命令重要)
另外,您应该使用mysqli_而不是mysql。
https://stackoverflow.com/questions/19689056
复制相似问题