I have a .php file which is responsible for managing news on a website, I need to filter by categories if the user presses a certain option on the menu. I am sending variables by means of php to the same file to later receive the value of the variable and translate it into my SQL query.
The problem is that entering the page for the first time gives me an error, since I am trying to recover the value of a variable that does not exist yet.
Does anyone know how I can solve this?
This is how I send my variables:
<li><a href="noticias.php">Todas</a> </li>
<li><a href="noticias.php?categoria=academicas">Academicas</a></li>
<li><a href="noticias.php?categoria=deportivas">Deportivas</a></li>
<li><a href="noticias.php?categoria=otras">Otras</a></li>
And this way I receive them in the same file noticias.php :
<?php
$consulta_tabla=($_GET['categoria']);
if($consulta_tabla == "deportivas"){
$categoria = "deportivas";
}else
if($consulta_tabla == "academicas"){
$categoria = "academicas";
}else
if($consulta_tabla == "otras"){
$categoria = "otras";
}
?>
Here is the problem, because when you load for the first time noticia.php $ consult_table has no value.