I am using PHP with OOP to select rows from the database (MySQL).
When I execute the query, it returns an empty row.
Here is the classe I am using:
<?php
class EmploiManager
{
private $_db;
public function __construct($db)
{
$this->setDb($db);
}
public function category($category)
{
$q = $this->_db->prepare('SELECT * FROM DemandeEmploi WHERE category = :category');
$q->execute(array('category' =>$category));
$donnees = $q->fetch(PDO::FETCH_ASSOC);
return new Emploi($donnees);
}
public function setDb(PDO $db)
{
$this->_db = $db;
}
}
$type = $_GET['category'];
$manager = new EmploiManager($db);
$row = $manager->category($type);
foreach ($row as $demandeE)
{
?>
<div class="list"><h4><a href="?id=<? echo $demandeE->id();?>&category=demandemploi"><? echo $demandeE->title();?></a></h4> </div>
<?php
}
?>
Can any one tell me what's wrong with that code? Thanks!
try/catchblock?query()instead ofprepare()it gives this error:Warning: PDO::query(): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'demploi' in 'where clause' in /opt/lampp/htdocs/gratisannonces.com/system/class/EmploiManager.class.php on line 28. But thedemploiit exists in the database in the column:categorydemoloiyour script saysdemploiand your code showsDemandeEmploithose are three different tables. Check it, because that is where your problem reliesdemoloiintodemploiit was an error of typing.demploiit is not the name of the table, it's a value in the database.