1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| <?php
class Groupe {
protected $id_group;
protected $designation;
protected $qte;
public function __construct(array $donnees)
{
$this->hydrate($donnees);
}
public function hydrate(array $donnees)
{
foreach ($donnees as $key => $value)
{
$method = 'set'.ucfirst($key);
if (method_exists($this, $method))
{
$this->$method($value);
// var_dump($value);
}
}
}
public function getId_group()
{
return $this->id_group;
}
public function getDesignation()
{
return $this->designation;
}
public function getQte()
{
return $this->qte;
}
public function setId_group($id_group)
{
$this->id_group = $id_group;
}
public function setDesignation($designation)
{
$this->designation=$designation;
}
public function setQte($qte)
{
$this->qte=$qte;
}
}
?>
---------------------------------------------------------------
<?php
class GroupeManager
{
private $_db;
public function __construct($db)
{
$this->setDb($db);
}
public function setDb(PDO $db)
{
$this->_db = $db;
}
public function getDb()
{
return $this->_db;
}
public function getListeGroupe($id_group)
{
$id_group = (int) $id_group;
$q = $this->_db->query('SELECT * FROM GROUPE_ARTICLES where id_group='.$id_group);
$donnees = $q->fetch(PDO::FETCH_ASSOC);
return new Groupe($donnees);
}
}
?>
-----------------------------------------------------------------------
<?php
$manager=new GroupeManager($db);
$a=$manager->getListeGroupe('1');
//print count($a);
//var_dump($a);
var_dump($designation);
?>
<table border align="center">
<tr>
<th>ID DU GROUPE</th>
<th>DESIGNATION</th>
<th>QUANTITE</th>
</tr>
<?php
foreach($a as $oneFood) { ?>
<tr>
<td><?php print $oneFood->getId_group();?></td>
<td><?php print $oneFood->getDesignation() ;?></td>
<td><?php print $oneFood->getQte();?></td>
</tr>
<?php
} ?>
</table> |
Partager