我有两个SQLb : SQLa和SQLb。SQLa从数据库中选择最新的9篇文章。另一种方法也是这样做的,但通过视图计数来订购文章。因此,我希望第二个SQL,即SQLb,不要选择在第一个SQL (SQLa)中选择的文章。
$sqla = "SELECT post_id, title, post_img, cnt FROM post ORDER BY post_id DESC LIMIT 9;";
$sqlb = "SELECT post_id, title, post_img, cnt FROM post ORDER BY cnt DESC LIMIT 9;";发布于 2020-10-29 11:01:43
使用WHERE post_id NOT IN (id,id,id,id),您可以排除前面选定的帖子。要获得这些id,必须循环第一个查询的结果,并将id存储在一个数组中。
$result.
$sqla并存储然后
$result:$not_in=[];foreach($result as $row){ /使用查询1/./将id存储在数组$not_in[]=$行‘’post_id‘中所需的值;}
$in =内爆( ',‘,$not_in);$sqlb =“按cnt DESC限制9按post_id NOT IN ($in)顺序从post中选择post_id,title,post_img,cnt;”;
https://stackoverflow.com/questions/64588962
复制相似问题