I have this code:
function enlaces($X){
$a = $this->db->query("SELECT * FROM enlaces WHERE codigo = '$X'");
if($a->num_rows()>=1){
return $a->fetch_array();
}else{
return false;
}
}
function paneles(){
$a = $this->db->query("SELECT * FROM paneles");
if($a->num_rows()>=1){
return $a->fetch_array();
}else{
return false;
}
}
$paneles = paneles();
if($paneles){
//Inicio la lista Principal
echo "<ul>";
foreach($paneles as $item){
//Inicio el Item de la Lista
echo "<li>".$item['titulo'];
$enlaces = enlaces($item['codigo']);
//Valido si hay enlaces para el codigo
if($enlaces){
//Si Hay enlaces inicio la sublista del item
echo "<ul>";
//Recorro los enlaces retornados
foreach($enlaces as $en){
//Agrego las URL
echo "<li>".$en['url']."</li>";
}
//Cierro la sub lista
echo "</ul>";
}else{
//Si no hay URLs indico el mensaje
echo "<li>Sin Enlaces para este panel</li>";
}
//Cierro el item principal
echo "</li>";
}
//Cierro la lista Completa
echo "</ul>";
}else{
//Si no hay paneles muestro el mensaje
echo "No hay paneles que mostrar";
}
With the following error: Fatal error: Using $ this when not in object context in
I understand that it is because This is not inside a class and here is where I get lost. What could be the class for the code to work well?
Additionally I am adding
db = mysqli_connect("localhost", "root", "roor", "flix");
function enlaces($X){
$a = $this->db->query($db, "SELECT * FROM enlaces WHERE codigo = '$X'");
but I do not know if this is the right thing to do.