Skip to content

Instantly share code, notes, and snippets.


Created Feb 2, 2016
What would you like to do?
Agrupar produtos por categoria.
$pdo = new PDO("mysql:host=localhost;dbname=loja", "root", "");
$sql = "SELECT,, AS categoryName, AS category_id FROM product p INNER JOIN category c ON c.product_id = ORDER BY ASC";
$results = $pdo->query($sql);
$group = '';
foreach($results as $result) : ?>
<?php if($group !== $result['category_id']) : ?>
<h2><?php echo $result['categoryName']?></h2>
<?php $group = $result['category_id']?>
<?php endif;?>
<p><?php echo $result['name']?></p>
<?php endforeach;?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.