我有下一个代码:
for (int lowsetLimit = 0, highestLimit = 10, i = lowsetLimit; i < highestLimit; i++)
{
//normal code which process before i gets eqaul to 5 goes here...
i = (i < 5) ? i : highestLimit; //and here is the pivot point.
}
我的bestellen.php是:
<?php
$rezOrders = mysqli_query($kon, "SELECT * FROM orders WHERE user_id = ". $user_id ." AND status = 0 ORDER BY id DESC LIMIT 1");
$redOrders = mysqli_fetch_assoc($rezOrders);
$rez = mysqli_query($kon, "SELECT shops.*, shops.naam as shopNaam, shops.id as shopId, shops.producten as shopEtalage, shops.bestel_extra as extra, shops.googlemaps as maps,
producten.*, producten.naam as prodNaam, producten.details as prodDetails, producten.id as prodID,
product_shop_tt.*, product_shop_tt.price as prodPrijs,
order_details.*, order_details.aantal as aantal, order_details.id as orderDetID,
type.*, type.naam as typeNaam
FROM order_details INNER JOIN product_shop_tt ON order_details.product_shop_tt_id = product_shop_tt.id
INNER JOIN shops ON shops.id = product_shop_tt.shop_id
INNER JOIN producten ON producten.id = product_shop_tt.product_id
INNER JOIN type ON type.id = shops.type_id
WHERE order_id = ". $redOrders["id"] ."");
$i = 1;
while($red = mysqli_fetch_assoc($rez)){
echo "<form action=\"bestellen.php?order_detail_id=". $red["orderDetID"] ."\" method=\"post\">";
echo "<input class=\"hidd\" type=\"hidden\" name=\"txtHidd[". $red["prodID"] ."][kolicina]\" id=\"txtHidd". $i ."\" value=\"". $red["aantal"] ."\"/>";
echo "<div class=\"col-xs-12 col-sm-12\" style=\"padding:0;\">
<div class=\"col-sm-2 col-xs-5\" style=\"margin-left:-10px;\" style=\"padding:0 0 0 3px;\">
<div class=\"form-group\">
<input id=\"quan". $i ."\" class=\"form-control\" type=\"number\" value=\"". $red["aantal"] ."\" onChange=\"proces('quan".$i."', 'txtHidd".$i."'); \"/>
</div>
</div>
<div class=\"col-sm-8 col-xs-5\" style=\"padding:0;\">
". $red["prodNaam"] ." (<strong>". $red["prodPrijs"] ."</strong>€) -- ". $red["prodDetails"] ."
</div>
<div class=\"col-sm-1 col-xs-1\" style=\"padding:0;text-align:right;\">
x
</div>
<div class=\"col-sm-1 col-xs-1\" style=\"padding:0;text-align:right;\">
<input type=\"checkbox\" name=\"chcWeek[". $red["prodID"] ."][]\" id=\"chcWeek\">
</div>
</div>";
$i++;
}
//Dugme za potvrdu narudzbe
echo "<div style=\"clear:both;\"></div><div class=\"footer\" style=\"position: fixed;bottom: 0;width: 100%;left:0;\">
<button type=\"submit\" class=\"col-xs-12 col-sm-12 btn btn-danger\" title=\"Bestel uw artikelen\">
Plaats bestelling <span class=\"glyphicon glyphicon-chevron-right\"></span>
</button>
</div>";
echo "</form>";
?>
在<?php
session_start();
include("config.php");
global $kon;
ob_start();
//Ovdje provjeravamo koji checkboxes su selektovani
if(!empty($_POST['chcWeek'])){
foreach ($_POST["chcWeek"] as $idProdChc => $prodIdChc) {
foreach($prodIdChc as $checkbox){
echo "Za id : ". $idProdChc ." Checkbox je ". $checkbox . "";
}
}
}
ob_flush();
}
中,如果选中该复选框,则会获得产品的ID和ON。但是,如何才能获得此bestellen.php
循环中的数量?
如果选中该复选框并且该产品的数量,我想获得该产品的ID。但我不能。我可以通过其他foreach循环从隐藏字段中获取产品ID和数量,但我不能将所有这三个组合在一起。
提前致谢。
我有这样的事情:
如何获取bestellen.php文件中输入字段的值(本例中为3)?
答案 0 :(得分:0)
据我了解,您希望在foreach循环中获得以下输入值:(为了便于阅读,我将\"
替换为'
)
<input id='quan". $i ."' class='form-control' type='number' value='". $red["aantal"] ."' onChange='proces('quan".$i."', 'txtHidd".$i."'); '/>
我没有看到名字=&#34;&#34;输入值,因此您必须先添加:
<input name='quan".$i."' id='quan". $i ."' class='form-control' type='number' value='". $red["aantal"] ."' onChange='proces('quan".$i."', 'txtHidd".$i."'); '/>
然后更新处理php代码以包含您的$i
变量和复选框。
//Ovdje provjeravamo koji checkboxes su selektovani
if(!empty($_POST['chcWeek'])){
$i = 1;
foreach ($_POST["chcWeek"] as $idProdChc => $prodIdChc) {
foreach($prodIdChc as $checkbox){
echo "Za id : ". $idProdChc ." Checkbox je ". $checkbox . "";
echo $_POST['quan'.$i]; // Your quantity in the input
$i++;
}
}
}
我相信你是如何获得数量的。 (或者你可能会将它移到外部的foreach而不是内部的那个?这对我来说似乎太复杂了。)