I want to select some results from my database but it must exclude the last 3 results which I got already.
The result I got already is in a string inside a foreach.
$result is a foreach string with three ID values (one for each), eg: 1, 2, and 3.
If I use $result in my query, it'll only exclude ID 3, because it's the last one.
This is what I've tried already, which works but only excludes the ID 3:
foreach ($pdo->query($sql) as $abc) {
$result = $abc['imp'];
}
SELECT * FROM t1 INNER JOIN t2 ON t1.cat = t2.id INNER JOIN t3 ON t1.aut = t3.id WHERE t1.imp <> $result AND t1.status = 1 ORDER BY t1.pub DESC LIMIT 3
What could I do to exclude all $result instead?
foreachloop you're using, and any directly relevant code from nearby, so that we can understand what you've tried so far, and your use case. Second, you should probably look to useNOT INinstead of<>; we can give more specifics once we see some code.WHERE t1.imp NOT IN (1,2,3) and t1.status = 1YOu'll want toimplode()the array into a comma delimited string to bind into theINlist your sql. Something like in the answer here or here.foreach. I triedNOT INusing a subquery but MySQL doesn't support it.NOT IN(). The only restriction is that the subquery can't useLIMIT.