for loop repeating single row
如果来自mysql数据库,我该怎么办?是否有购物车页面和for($i=0;$i<=$max;$i++){
循环从 mysql 数据库重复单行?以及如何在 for 循环中从数据库中检索多行?
查询功能
function get_size(){
$result=mysql_query("SELECT size FROM mywishlist order by id")
or die("My Wish Size Problem"."<br/><br/>".mysql_error());
while($row=mysql_fetch_array($result)){
return $row['size'];
}}
购物车页面
<?php
if(is_array($_SESSION['cart'])){
echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td align="center"><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Product Name</font></td>
<td align="center"><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Product Image</font></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Price</font></td>
<td><div><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Size</font></div></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Amount</font></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Options</font></td></tr>';
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$id=$_SESSION['cart'][$i]['id'];
$q=$_SESSION['cart'][$i]['qty'];
$product=get_product_name($id);
$image=get_product_image($id);
$ids=get_id($id);
$itemcode=get_itemcode($id);
$size=get_size($id);
if($q==0) continue;
?>
<tr bgcolor="#FFFFFF"><td align="center"><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"><input type="hidden" name="itemcode[]" value="<?php echo $itemcode?>" /><input type="hidden" name="ids[]" value="<?php echo $ids?>" /><input type="hidden" name="product[]" value="<?php echo $product?>" /><?php echo $product?></font></td><td align="center"><input type="hidden" name="image[]" id="image" value="<?php echo $image?>" /><img name="image" id="image" src="admin/uploads/small0_<?php echo $image?>" width="150" height="150"></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"> <input type="hidden" name="price[]" id="price" value="<?php echo get_price($id)?>"/>Rs.<?php echo get_price($id)?></font></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"><?php echo $size ?></font><input type="hidden" name="size" value="<?php echo $size?>" /></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"><input type="hidden" name="amt[]" value="<?php echo get_price($id)*$q?>"/> Rs.<?php echo get_price($id)*$q?></font></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"><a href="javascript:del(<?php echo $id?>)"><input type="button" class="button5" value="Remove" /></a></font></td></tr>
<?php
}
?>
<tr><td colspan="6" align="right"><b><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"><input type="hidden" name="total" id="total" value="<?php echo get_order_total()?>"/>Order Total:Rs.<?php echo get_order_total()?></font></b></td></tr>
<tr><td colspan="6" align="right"><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000; !important">Cash On Delivery & Free Shipping</font></td></tr>
<tr><td colspan="6" align="right">
<?php $query1=mysql_query("SELECT * FROM category ORDER BY id ") or die ('Product Query Problem');
$row4=mysql_fetch_array($query1);$ids=$row4['id'];$cat_name=$row4['categories'];?> <input type="button" class="button1" value="Continue Shopping" onclick="window.location='product.php'" /><input type="button" class="button2" value="Clear Cart" onclick="clear_cart()"><input type="button" class="button3" value="Update Cart" onclick="update_cart()"><input type="submit" class="button4" name="order" id="order" value="Place Order"></td></tr>
<?php
}
else{
echo "<tr bgColor='#FFFFFF'><td><font style='font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;'>There are no items in your shopping cart!</font></td>";
}
?>