添加到购物车按钮没有显示在说明的底部

时间:2015-04-27 06:41:50

标签: php

* addtocart按钮出现在图片的顶部。所有产品只有一个按钮。如何让每个产品都有自己的addtocart buttton?

$sql=mysql_query("SELECT * FROM product ORDER BY product_id DESC LIMIT 15    
");
$i=0;
$dyn_table='<table border="1" cellpadding="10">';
$name = 'name';
$image = 'image';
$category = 'category';
$color = 'color';
$description = 'description';
$price = 'price';

while($row=mysql_fetch_assoc($sql)){

$product_id=$row['product_id'];
$name = $row['name'];
$image = $row['image'];
$category = $row['category'];
$color = $row['color'];
$description = $row['description'];
$price = $row['price'];
$image = $row['image'];

if($i % 5 == 0){
$dyn_table.='<tr><td>'.$name.'<br /><img src="img/'.$image.'" width="200"     
height="90" align="center"><br /><p>'.$description.'</p></td>'
.'<input type="button" value="Add to Cart" onclick="addtocart $product_id" 
/>';
} else {
$dyn_table.='<td>'.$name.'<br /><img src="img/'.$image.'" width="200"   
height="90" align="center"><br /><p>'.$description.'</p></td>';
}
$i++; }
$dyn_table.='</tr></table>';
?>

<?php echo $dyn_table;?>

1 个答案:

答案 0 :(得分:1)

您可以使用foreach函数循环遍历每个值并将添加到购物车按钮

while($row=mysql_fetch_assoc($sql)){
       foreach($row as $value){
         //you data $vlaue[]
              ?>
        <button>Add to Cart</button>
         <?php
         }
  }