-1
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 'loja_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->execute() #1 C: xampp htdocs lojacurso pages categoria.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
}
?>
When shooting points out the following error: Fatal error: Call to Undefined method Pdostatement::rowCont() in C: path classes Site.class.php on line 10"
– Leonardo Henrique
I saw here the spelling error :D
– Leonardo Henrique
"Count" and not "cont" as it was
– Leonardo Henrique