-1
$inter = $pdo->query("SELECT * FROM noticias WHERE status = 'ativo' AND fixo != 's' AND comentarios != 's' ORDER BY id DESC LIMIT 5");
$i = 1;
$num = '';
while($in = $inter->fetch()) {
if($i == 1){
$num .= "'".$in['id']."', ";
}elseif($i == 2){
$num .= "'".$in['id']."', ";
}elseif($i == 3){
$num .= "'".$in['id']."', ";
}elseif($i == 4){
$num .= "'".$in['id']."', ";
}elseif($i == 5){
$num .= "'".$in['id']."'";
}
$noticias = $pdo->query("SELECT * FROM noticias WHERE status='ativo' AND cat_id='Notícias' AND fixo != 's' AND comentarios != 's' AND id NOT IN ( $num ) ORDER BY id DESC LIMIT 3");
echo $num;
$i++;}
while ($not = $noticias->fetch(PDO::FETCH_ASSOC)) {
The error happens in Where AND id NOT IN ( $num ), as $num is not working in NOT IN, but is normal in echo, how to solve?
And on the way out of
echo
there is a comma at the end? In fact, what is thisif
should do? It runs the same code, independent of$i
.– Woss
I think the problem is the query is running inside the while, I don’t really understand why to do all this.
– Inkeliz
if I used to remove the last comma, I’m trying to remove the id values from the first query
– Paulo Sérgio Filho