Телефоны
galaxy s3
белый - 300
xperia
черный - 250
Ноутбуки
lenovo
зеленый - 130
chromebook
зеленый - 120
красный - 150
синий - 70
Телевизоры
philips
серый - 200
$query = query('SELECT FROM * категории');
while ($res = array($query)){
echo $res[cat_name];
$query2 = query('SELECT * FROM товары WHERE catid=$res[id]');
while ($res2 = array($query2)){
echo $res2[product_name];
$query3 = query('SELECT * FROM варианта WHERE product_id=$res2[id]');
while($res3 = array($query3)) {
echo $res3[variant_name];
}
}
}
<?
$sql = <<< TXT
SELECT
cats.id as catsid, prod.id as prodid, cats.cat_name, prod.product_name, vars.variant_name
FROM категории cats, товары prod, варианты vars
WHERE
cats.id = prod.cat_id
AND prod.id = vars.product_id
ORDER BY cats.id, prod.id
TXT;
...
$cat_id = -1;
$prod_id = -1;
foreach( ... as $line){
if($cat_id != $line['catsid']){
$cat_id = $line['catsid'];
$prod_id = -1;
echo $line['cat_name'], "\n";
}
if($prod_id != $line['prodid']){
$prod_id = $line['prodid'];
echo "\t", $line['product_name'], "\n";
}
echo "\t\t", $line['variant_name'], "\n";
}
select * from категории, товары, варианты
where варианты.product_id = товары.id and товары.cat_id = категории.id