I have this problem ,I have a 'products table' and it contains products description, price, category, subcategory and a few other rows.
I have this php block that is supposed to retrieve and echo an dynamic accordion with categories and subcategories and trim the duplicates.
I feel like I'm close but I might be miles away..
<?php
$sql = mysql_query("SELECT DISTINCT category FROM products");
while($row = mysql_fetch_array($sql)) {
$category = $row['category'];
$sql2 = mysql_query("SELECT DISTINCT subcategory FROM products WHERE category = '$category'");
while($row = mysql_fetch_array($sql2)) {
$subcategory = $row['subcategory'];
echo '<h3><a href="#">'.$category.'</a></h3>
<div>
<p><a href="#">'.$subcategory.'</a></p>
</div>';
}}
?>
The problem is that I'm getting duplicated Categories..
mysql_*
functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy. – Jay Blanchard