|
|
|
คำนวณ array อัตโนมัติ ( ราคาอาหาร ) ใช้ในการแก้ไขเพื่อเก็บข้อมูลบันทึกใหม่ |
|
|
|
|
|
|
|
Code (PHP)
$sql1 = mysqli_query($connection,"select * from restaurant_orders where orderno = '".$_POST['id']."'");
$num1 = mysqli_num_rows($sql1);
$arr=mysqli_fetch_array($sql1);
$ordidarray = explode("@",$arr[11]);
$ordnumarray = explode("@",$arr[12]);
$option = '';
$i = 101;
// while($row = $sql1->fetch_assoc () ){
// $i++;
// $option .= '<option value="'.$row['id'].'">'.$row['title'].'</option>';
for($i=1; $i<count($ordidarray); $i++)
{
$product = get_product_details_1($ordidarray[$i]);
$price1 = $product['price'];
$price2 = $product['sale'];
if($price2 < $price1) {
$realprice = $price2;
} else {
$realprice = $price1;
}
$pid = $product['mainid'];
$image = get_catalog_image($pid);
$imarray = explode("@",$image['picture']);
$img = $imarray[0];
?>
<div id="div<?php echo $i ?>">
<div class="row" >
<div >
<?php $title = stripslashes($product["title"]);
$sql2 = mysqli_query($connection,"select * from restaurant_product where title = '".$title."'");
$arr=mysqli_fetch_assoc($sql2);
$mainid = $arr['id'];
// $num1 = mysqli_num_rows($sql1);
?>
ชื่ออาหาร <select name="productid[]" id="productid" class="form-control" style="width:150px;" >
<option value="<?php echo $mainid; ?>"><?php echo $title ?></option>
<!-- <?php echo $option1; ?> -->
</select>
ราคาต่อหน่วย
<?php
if($price2 < $price1) {
echo "<input type=\"text\" name=\"pid\" id=\"pid\" style=\"width:50px;\" value='".number_format($price2,2)."' readonly>บาท";
} else {
echo "<input type=\"text\" name=\"pid\" id=\"pid\" style=\"width:50px;\" value='".number_format($realprice,2)."' readonly >บาท";
}
?>
<!-- <input type="text" name="" value="" style="width:50px;"> -->
จำนวน<input type="text" name="num" id="num" value="<?php echo $ordnumarray[$i] ?>" style="width:50px;" >
ราคารวม<input type="text" name="total" id="total" value="<?php echo number_format(($realprice*$ordnumarray[$i]),2) ?>" style="width:50px;" readonly>
<?php
$totalprice = $totalprice + ($realprice*$ordnumarray[$i]);
?>
<!-- <button type="button" class="btn btn-danger delete" id="<?php echo $i; ?>"><i class="fa fa-minus" style="margin-right:10px;" aria-hidden="true"></i>ลบ</button> -->
</div>
</div>
</div>
<?php
}
$i++;
echo "รวม :" .$totalprice.""
|
|
|
|
|
Date :
2018-07-27 13:26:11 |
By :
2037881702931155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|