我在while循环中有一些php变量,它们根据产品ID从表中的列收集数据,但结果为" care0,care3,care5"仅响应添加的第一个ID - 对于所提及的变量,后续产品ID没有累积添加。
<?php
$con = mysqli_connect("localhost","user","password","database");
global $con;
$ip = getIp();
$sel_price = "select * from products where ip_address='$ip'";
$run_price = mysqli_query($con, $sel_price);
while ($p_price=mysqli_fetch_assoc($run_price)){
$pro_id = $p_price['product_id'];
$pro_price = "select * from products where product_id='$pro_id'";
$run_pro_price = mysqli_query($con, $pro_price);
while ($pp_price = mysqli_fetch_assoc($run_pro_price)){
$product_id = $pp_price['product_id'];
$product_type = $pp_price['product_type'];
$product_category = $pp_price['product_category'];
$product_brand = $pp_price['product_brand'];
$product_model = $pp_price['product_model'];
$product_price = array($pp_price['product_price']);
$product_install = $pp_price['product_install'];
$product_delivery = '20.00';
$product_recycle = '15.00';
//Problem Starts Here
$care0 = '0.00';
$care3 = $pp_price['care3'];
$care5 = $pp_price['care5'];
//Problem ends here
$product_title = $pp_price['product_title'];
$product_image = $pp_price['product_imagelist'];
$single_price = $pp_price['product_price'];
$values = array_sum($product_price);
$subtotal += $values;
$fulltotal = $subtotal+$product_delivery+$product_install+$product_recycle;
?>
变量的结果在3个单选按钮的值中回显,并在提交表单时更新,然后金额在相邻的div中回显。
<html>
<div class="bask-tot3"><p class="nobr"><span class="grey-lite">Extended Warranty <span class="blue-link"><a href="warranty" title="find out about extended warranties...">find out more</a></span><br/><br/></span></p>
<p class="nobr"><input type="radio" name="care" value="<?php echo $care0; ?>" checked="checked" /> No thanks</p>
<p class="nobr"><input type="radio" name="care" value="<?php echo $care3; ?>" /> 3 years</p>
<p class="nobr"><input type="radio" name="care" value="<?php echo $care5; ?>" /> 5 years</p>
</div>
<div class="bask-tot4"><p><?php echo £ . $_POST["care"]; ?></p></div>
</html>
如您所见,care3和care5来自表数据,但care0不是。
多个产品价格的计算器$ product_price工作正常,因为它在一个数组中,但多个护理包价格的计算器只响应添加的第一个项目。我想我错过了一个foreach语句,或者需要将这三个变量放到一个数组中,但我对如何实现它感到茫然。