0
I have the index that contains my class call CRUD
and the foreach
calling the class method crud
. But within the foreach
I’m trying to pass the table name parameter, but it shows nothing. If I take the parameter and put the table name inside the method, it works well. I don’t know what I do! =/
Index:
<?php
require_once('classes/crud.class.php');
$mostrarpar = new crud();
?>
<?php foreach ($mostrarpar->Listar('moedas_par') as $res) { ?>
<li><?php echo $res['par_nome']; ?></li>
<?php } ?>
CRUD:
public function Listar($table) {
$this->query = $this->setConn()->prepare("SELECT * FROM'.$table.'");
$this->query->execute();
return $this->query->fetchall(PDO::FETCH_ASSOC);
}
Have you tried it print_r($res) or var_dump($res) to see if that answer has what you want?
– ShutUpMagda
Try it like this
$this->query = $this->setConn()->prepare("SELECT * FROM ".$table);
, was missing a space between the table name and theFROM
, and the concatenation was wrong– Augusto
Putz, what a mistake! hehe, thank you Augusto. Fixed and working perfectly. ;)
– Joao Marcos