Hola, acabo de volver con PHP y recuerdo que yo para validar si existia algun dato en la db y en el caso de existir crear un while, he probado muchas formas y no me funcionan(Solo de 1 forma)
Código PHP:
<?php
//Buscador de categoria
$category = mysqli_query($db, "SELECT id,title,imagen,message,category,date FROM news WHERE category = '".mysqli_real_escape_string($db, urldecode($_GET['category']))."'");
if($category1 = mysqli_fetch_assoc($category)):
while($category1 = mysqli_fetch_assoc($category)):
?>
<article>
.....
</article>
<?php
endwhile;
else:
header('Location: /404.html');
endif;
Código PHP:
<?php
//Buscador de categoria
$category = mysqli_query($db, "SELECT id,title,imagen,message,category,date FROM news WHERE category = '".mysqli_real_escape_string($db, urldecode($_GET['category']))."'");
while($category1 = mysqli_fetch_assoc($category)):
?>
<article>
.....
</article>
<?php
endwhile;
if(!$category1 = mysqli_fetch_assoc($category)):
header('Location: /404.html');
endif;
La unica manera que me funciona es haciendo 2 veces la sentencia:
Código PHP:
<?php
//Buscador de categoria
$category = mysqli_query($db, "SELECT id,title,imagen,message,category,date FROM news WHERE category = '".mysqli_real_escape_string($db, urldecode($_GET['category']))."'");
if($category3 = mysqli_fetch_assoc($category)):
$category2 = mysqli_query($db, "SELECT id,title,imagen,message,category,date FROM news WHERE category = '".mysqli_real_escape_string($db, urldecode($_GET['category']))."'");
while($category1 = mysqli_fetch_assoc($category2)):
?>
<article>
.....
</article>
<?php
endwhile;
else:
header('Location: /404.html');
endif;
¿Porque tengo que hacer 2 consultas para que me funcione?