我不知道如何设置id字段在下面的脚本中逐行打印,这会产生奇迹。
$tree = array();
$sql = "select * from products
left join product_varieties on product_varieties.product_id = products.id";
$sth = query($sql);
while($row = fetch($sth)) {
$id = $row['id'];
$tree[$id]['name'] = $row['name'];
if($row['variety'])
$tree[$id]['varieties'][] = $row;
}
foreach($tree as $product)
<div>
echo $product['name']
foreach($product['varieties'] as $variety)
etc etc
</div>
我一直在尝试使用在foreach父级中的表单操作url字符串中的while循环中生成的id,因为在partent foreach中使用了名称索引。我已经尝试回显并打印一些如何不显示id或者如果我打印它,那么每行会出现三行ID,如111333444555,我只想拥有每行的id,如echo $ product ['name'],每次迭代只打印索引['name']的一行。
下面的表单不会回显任何内容,我将其更改为打印然后将打印111222333444帮助..
foreach($tree as $product){
<form action="cart.php?id="'. echo $product['id']. '">
</form>
<div> echo $product['name'] echo $procude['id']
foreach($product['varieties'] as $variety) {
etc etc
</div>
}
}
答案 0 :(得分:0)
不确定我是否理解你想要的东西..但是让我试试:
foreach($tree as $id=>$product){
echo "<div>".$id." ".$product['name'];
foreach($product['varieties'] as $variety){
// whatever
}
echo "</div>";
}