I am trying to list the categories and subcategories present in the database but the following error is pointed out:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' store_categories' ORDER BY id DESC 'at line 1' in C: \ xampp \ htdocs \ lojacurso \ classes \ Site.class.php: 8 Stack trace: # 0 C: \ xampp \ htdocs \ lojacurso \ classes \ Site.class.php (8): PDOStatement-> Run () # 1 C: \ xampp \ htdocs \ lojacourse \ pages \ category.php (13): Site-> getMenu () # 2 C: \ xampp \ htdocs \ lojacurso \ index.php (20): include_once ('C: \ xampp \ htdocs ...') # 3 {main} thrown in C: \ xampp \ htdocs \ lojacurso \ classes \ Site.class.php on line 8
The code is this:
<?php
class Site extends BD{
public function getMenu(){
$pegar_categorias = "SELECT * FROM 'loja_categorias' ORDER BY id DESC";
$executar = self::conn()->prepare($pegar_categorias);
$executar->execute();
if ($executar->rowCont() == 0) {
# não faz nada pois não há categorias
}else{
while ($categoria = $executar->fetchObject()) {
echo '<li><a href="'.PATH.'/categoria/'.$categoria->slug.'">'.$categoria->titulo.'';
$pegar_subcategorias = "SELECT * FROM 'loja_subcategorias' WHERE id_cat = ?";
$executar_sub = self::conn()->prepare($pegar_subcategorias);
$executar_sub->execute(array($categoria->id));
if ($executar_sub->rowCont() == 0) {
echo '</li>';
}else{
echo '<ul>';
while ($subcategoria == $executar_sub->fetchObject()) {
echo '<li><a href=" '.PATH.'/categoria/'.$categoria->slug.'/'.$subcategoria->slug.' ">'.$subcategoria->titulo.'</a></li>';
}//termina while subcategoria
echo '</ul></li>';
}//termina else dos resultados da subcategoria
}//termina while das categorias
}//primeiro else
}//TERMINA FUNÇÃO getMenu
}
?>