我创建了一个购物车,由于某种原因,它没有向paypal添加另一个项目。它只发送一个项目。我有要在数据库中添加的项目列表,我循环遍历它们。
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="test@test.com" />
<div class="basket_block" id="basket_block">
<div class="checkout_inv" id="checkout_inv">Invoice: OCA1234</div>
<?php
$sql_cart="SELECT * FROM cart_table where session_id = '$sessionid'";
$result_set_cart=$database->query($sql_cart);
$num_rows_cart=$database->num_rows($result_set_cart);
for($i=1;$i<=$num_rows_cart;$i++)
{
while ($row_cart=$database->fetch_array($result_set_cart)){
$prod_id_now=$row_cart['products_id'];
$quantity_now=$row_cart['quantity'];
$grand_total_now =$row_cart['grand_total'];
$sql_product = "Select * from products where id = '$prod_id_now'";
$result_set_product = $database->query($sql_product);
while ($row_product=$database->fetch_array($result_set_product)){ $titleofmessage = $row_product['Title_of_Message']; $type_id = $row_product['type_id'];}
$sql_type = "Select * from type where id = '$type_id'";
$result_set_type = $database->query($sql_type);
while ($row_type=$database->fetch_array($result_set_type)){ $typename = $row_type['name'];}
?>
<div class="checkout_des" id="checkout_des"> <?php
echo 'Title: '.html_entity_decode($titleofmessage).'<br>'.'Tpye: '.$typename.'<br>'.'Quantity: '.$quantity_now."<P>";
?></div>
<div class="checkout_amount" id="checkout_amount"><?php echo 'R '.number_format($grand_total_now,2); ?></div>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo html_entity_decode($titleofmessage); ?>" />
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $quantity_now; ?>" />
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $grand_total_now; ?>" />
<?php
}
}
?>
</div>
答案 0 :(得分:2)
添加$ i ++;你需要增加你的循环
<div class="checkout_amount" id="checkout_amount"><?php echo 'R '.number_format($grand_total_now,2); ?></div>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo html_entity_decode($titleofmessage); ?>" />
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $quantity_now; ?>" />
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $unit_cost; ?>" />
<?php
$i++;
}
}
?>