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
| <?php session_start();
$dbh = new PDO("mysql:host=localhost;dbname=asdf", 'root', '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$categorie = isset($_GET['catalog']) ? $_GET['catalog'] : 'peinture' ;
$lenombre = $dbh->prepare("
SELECT
categorie.categorie,
users.id,
users.firstname,
users.lastname,
COUNT(*) AS nb
FROM
categorie
INNER JOIN images ON categorie.id = images.categorieid
INNER JOIN users ON images.usersid = users.id
WHERE
categorie = :categorie
ORDER BY
categorie.id DESC,
users.id DESC
");
$lenombre->bindValue(':categorie', $categorie, PDO::PARAM_STR);
$lenombre->execute();
while ($compte = $lenombre->fetchObject())
{ $_SESSION['compte'] = $compte->nb; }
$stmt = $dbh->prepare("
SELECT
categorie.categorie,
users.id,
users.firstname,
users.lastname
FROM
categorie
INNER JOIN images ON categorie.id = images.categorieid
INNER JOIN users ON images.usersid = users.id
WHERE
categorie = :categorie
ORDER BY
categorie.id DESC,
users.id DESC
");
$stmt->bindValue(':categorie', $categorie, PDO::PARAM_STR);
$stmt->execute();
if (!$stmt->rowCount() == 0)
{
$cat = "";
while ($row = $stmt->fetchObject())
{
if($row->categorie != $cat)
{
$cat = $row->categorie;
echo 'Dans la catégorie «<strong>'.ucfirst($cat).'</strong>», il y en a <strong>'.$_SESSION['compte'].'</strong> :';
}
echo '<hr>'.$row->firstname.' '.$row->lastname;
}
echo '<hr>';
}
else
{
echo 'Aucun enregistrement trouvé correspondant à votre requête.';
}
?> |
Partager