lundi 10 août 2015

how can I also get the quantity in the foreach loop?

I have next code :

<?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>";


?>

My bestellen.php is :

    <?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();
}

In bestellen.php I get the id of the product and ON if the checkbox is checked. But how can I also get the quantity in this foreach loop?

I would like to get id of the product, if the checkbox is checked and the quantity for that product. But i can't. I can get the product id and the quantity from hidden field with other foreach loop, but i can't get all three together.

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire