upside
Jun 25th 2006, 2:23 pm
This is really easy, but sadly that's not helping me make it work.
I've got a database of products arranged in increasing degrees of specificity:
category then subcategory then product_group. Category is passed in the url. I want to then iterate through unique subcats for that category (this part works). Then I want to also find the unique product_groups for each subcat. So if "clothes" was passed in the url I want the page to have subcat "pants, shirts, hats" with product_groups "long pants, short pants" and "yellow shirts, blue blue shirts, etc." Here's where I am:
<?
//get passed variable
$category = $_REQUEST['id'];
//run first query
$sql = "SELECT DISTINCT subcategory FROM my_cms WHERE category='$category'";
$subcat_array = $DB->query($sql);
$counter = 0;
foreach($subcat_array as $subcategory) {
$counter++;
//run second query on the results of the first
$product_sql="SELECT DISTINCT product_group FROM my_cms WHERE subcategory='$subcategory'";
$group_array=$DB->query($product_sql);
foreach($group_array as $product_group)
//iterate through each query post each result as a link - this also works, or //worked, for the first query
{
echo "$counter. <a href='subcategory.php?id=".$subcategory["subcategory"]."'>".$subcategory["subcategory"]."</a>:: <BR><BR>";
echo "$counter. <a href='subcategory.php?id=".$subcategory["subcategory"]."'>".$product_group["product_group"]."</a>:: <BR><BR>";
}
}
?>
It's basically the exact same query again inside the foreach(), and since it works in the first I can't figure out why not in the second. I am guessing that I am not passing the variable correctly - but for the life of me I can't figure out how. If anyone has any thoughts, that would be swell.
I've got a database of products arranged in increasing degrees of specificity:
category then subcategory then product_group. Category is passed in the url. I want to then iterate through unique subcats for that category (this part works). Then I want to also find the unique product_groups for each subcat. So if "clothes" was passed in the url I want the page to have subcat "pants, shirts, hats" with product_groups "long pants, short pants" and "yellow shirts, blue blue shirts, etc." Here's where I am:
<?
//get passed variable
$category = $_REQUEST['id'];
//run first query
$sql = "SELECT DISTINCT subcategory FROM my_cms WHERE category='$category'";
$subcat_array = $DB->query($sql);
$counter = 0;
foreach($subcat_array as $subcategory) {
$counter++;
//run second query on the results of the first
$product_sql="SELECT DISTINCT product_group FROM my_cms WHERE subcategory='$subcategory'";
$group_array=$DB->query($product_sql);
foreach($group_array as $product_group)
//iterate through each query post each result as a link - this also works, or //worked, for the first query
{
echo "$counter. <a href='subcategory.php?id=".$subcategory["subcategory"]."'>".$subcategory["subcategory"]."</a>:: <BR><BR>";
echo "$counter. <a href='subcategory.php?id=".$subcategory["subcategory"]."'>".$product_group["product_group"]."</a>:: <BR><BR>";
}
}
?>
It's basically the exact same query again inside the foreach(), and since it works in the first I can't figure out why not in the second. I am guessing that I am not passing the variable correctly - but for the life of me I can't figure out how. If anyone has any thoughts, that would be swell.