开发者

I need this script to print the id field one per iteration no all row by iterations help

I don't know how 开发者_开发问答to set up that the id field to print one by one per row in the script below which works wonders.

$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>

I have been trying to use the id generated in the while loop inside the form action url string inside the foreach parent as you use the name index in the partent foreach. I have tried echoing and printing some how it won't display the id or if I print it, then it will appear three rows of ids per rows like 111333444555, I just want to be able to have the id per row like echo $product['name'] does, each iteration only prints one row of the index [ 'name'].

The form below won't echo anything, and I I change it to print then it will print 111222333444 help..

 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> 
}
}


not sure i understand correctly what you want.. but let me try:

foreach($tree as $id=>$product){
    echo "<div>".$id." ".$product['name'];
    foreach($product['varieties'] as $variety){
       // whatever 
    }

    echo "</div>";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜