|
|
|
Invalid argument supplied for foreach() in ช่วยด้วย |
|
|
|
|
|
|
|
Code (PHP)
<?php
include 'asset/class/functions.php';
include 'asset/class/db.functions.php';
htmlhead();
/*
function getmembername()
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT username FROM member WHERE club_type='0'");
$stm->execute();
if($stm->rowCount() > 0){
$result = $stm->fetchall(PDO::FETCH_ASSOC);
//$result = $stm->fetchAll(PDO::FETCH_COLUMN);
foreach($result as $value){
$arrays = null;
foreach($value as $subvalue){
$arrays[] .= $subvalue;
}
}
}
}catch(PDOException $ex){
echo $ex->getMessage();
$result = null;
}
return json_encode($arrays);
}
function getproductintype($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT id,prod_type,prod_name,prod_price,prod_unit,prod_detail FROM product WHERE prod_type=:type AND status='1'");
$stm->bindparam(":type",$value);
$stm->execute();
if($stm->rowCount() > 0){
$result = $stm->fetchAll(PDO::FETCH_ASSOC);
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
function checkbooking($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT prod_id,status FROM orders_detail WHERE order_id=:order_id");
$stm->bindparam(":order_id",$value);
$stm->execute();
if($stm->rowCount() > 0){
$checker = $stm->fetchAll(PDO::FETCH_ASSOC);
foreach ($checker as $checkvalue) {
# code...
if(getprodtype($checkvalue['prod_id']) ==1) {
$result = $checkvalue['prod_id'];
}
}
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
function canbooking($id,$starttm,$stoptm)
{
# code...
$result = false;
try{
$stm = connectdb()->prepare("SELECT status FROM booking WHERE book_on=:id AND (book_start=:starttime OR (book_start<:starttime AND :starttime<book_stop) OR book_stop=:stoptime OR (book_start<:stoptime AND :stoptime<book_stop)) AND status!=0");
$stm->bindparam(":id",$id);
$stm->bindparam(":starttime",$starttm);
$stm->bindparam(":stoptime",$stoptm);
$stm->execute();
if($stm->rowCount() == 0){
$result = true;
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
*/
function getname($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT fname,lname,username FROM member WHERE club_id=:club_id AND status='1' LIMIT 1");
$stm->bindparam(":club_id",$value);
$stm->execute();
if($stm->rowCount() == 1){
$result = $stm->fetch(PDO::FETCH_ASSOC);
}
}catch(PDOException $ex){
echo $ex->getMessage();
$result = null;
}
return $result;
}
function getprodtype($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT prod_type FROM product WHERE id=:prod_id AND status='1' LIMIT 1");
$stm->bindparam(":prod_id",$value);
$stm->execute();
if($stm->rowCount() == 1){
$result = $stm->fetch(PDO::FETCH_ASSOC)['prod_type'];
}
}catch(PDOException $ex){
echo $ex->getMessage();
$result = null;
}
return $result;
}
function booking_detail($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT member_id,book_start,book_stop,book_on,status FROM booking WHERE order_id=:order_id LIMIT 1");
$stm->bindparam(":order_id",$value);
$stm->execute();
if($stm->rowCount() > 0){
$result = $stm->fetch(PDO::FETCH_ASSOC);
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
function getbooking($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT prod_name FROM product WHERE id=:id AND prod_type='1' LIMIT 1");
$stm->bindparam(":id",$value);
$stm->execute();
if($stm->rowCount() == 1){
$result = $stm->fetch(PDO::FETCH_ASSOC)['prod_name'];
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
function getorderlist($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT id,prod_id,prod_value,cost,status FROM orders_detail WHERE order_id=:order_id");
$stm->bindparam(":order_id",$value);
$stm->execute();
if($stm->rowCount() > 0){
$result = $stm->fetchAll(PDO::FETCH_ASSOC);
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
function getprod_name($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT prod_name FROM product WHERE id=:id LIMIT 1");
$stm->bindparam(":id",$value);
$stm->execute();
if($stm->rowCount() == 1){
$result = $stm->fetch(PDO::FETCH_ASSOC)['prod_name'];
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
function getprod_unit($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT prod_unit FROM product WHERE id=:id LIMIT 1");
$stm->bindparam(":id",$value);
$stm->execute();
if($stm->rowCount() == 1){
$prod_unit = $stm->fetch(PDO::FETCH_ASSOC)['prod_unit'];
if($prod_unit == 1){ $result = "หน่วย";}
if($prod_unit == 2){ $result = "ชั่วโมง";}
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
function getbilling($value)
{
# code...
$result = null;
try{
$stm = connectdb()->prepare("SELECT pay,cost,status FROM billing WHERE order_id=:order_id");
$stm->bindparam(":order_id",$value);
$stm->execute();
if($stm->rowCount() > 0){
$result = $stm->fetchAll(PDO::FETCH_ASSOC);
}
}catch(PDOException $ex){
echo $ex->getMessage();
}
return $result;
}
if(checksignin()){
gen_topdiv();
echo '<link rel="stylesheet" href="asset/style/sidenav.css">
<div id="maindiv">
<div id="sidebar" class="sidenav">
</div>
<div id="main" class="main">';
//if(isset($_SESSION['ses01']) && userlevel(base64_decode($_SESSION['ses01']))['club_type'] == 2){
if(isset($_SESSION['ses01'])){
gen_linkbar(userlevel(base64_decode($_SESSION['ses01']))['club_type']);
if(!empty($_GET)) {
$data = booking_detail(base64_decode($_GET['oid']));
$membername = getname($data['member_id']);
$memberuname = $membername['fname']." ".$membername['lname']." (".$membername['username'].")";
//$ondate = date('m/d/Y',$data['book_start']);
$ondate = getthaidate($data['book_start']);
$starthh = date('H:i',$data['book_start']);
$stophh = date('H:i',$data['book_stop']);
$dutytime = ($data['book_stop']-$data['book_start'])/3600;
$dutyhh = floor($dutytime);
$dutymm = $dutytime-$dutyhh;
$bookon = getbooking($data['book_on']);
echo '<form id="billorder" name="billorder" method="post" action="action.order.php" autocomplete="off" class="text-left" enctype="multipart/form-data"><input type="hidden" name="order_id" value="'.base64_decode($_GET['oid']).'"><input type="hidden" name="formin" value="editorder"><input type="hidden" name="from_url" value="'.geturl().'">
<h3 class="text-center">รายการสั่งซื้อ</h3>
<div class="row">
<div class="col-a"><label for="oforid">สมาชิก</label></div>
<div class="col-b">'.$memberuname.'</div>
</div>
<link rel="stylesheet" href="asset/style/jquery-ui-timepicker-addon.css">
<script src="asset/js/jquery-ui-timepicker-addon.js"></script>
<div class="row">
<div class="col-a"></div>
<div class="col-b">
</div>
</div>
<div class="row">
<div class="col-a"><label>วันที่ใช้บริการ</label></div>
<div class="col-b"><p>'.$ondate.'</div>
</div>
<div class="row">
<div class="col-a"><label>เวลาเริ่ม</label></div>
<div class="col-b"><input type="hidden" name="ostarttime" value="'.$data['book_start'].'">'.$starthh.'น.</div>
</div>
<div class="row">
<div class="col-a"><label>เวลาสิ้นสุด</label></div>
<div class="col-b"><input type="hidden" name="ostoptime" value="'.$data['book_stop'].'">'.$stophh.'น.</div>
</div>
<div class="row">
<div class="col-a"><label for="oduty">จำนวน(ชั่วโมง)</label></div>
<div class="col-b"><div name="oduty"><p>'.$dutyhh.' ชั่วโมง '.str_pad($dutymm,2,"0",STR_PAD_LEFT).' นาที</p></div>
</div>
</div>
<div class="row">
<div class="col-a"><label>รายการ</label></div>
<div class="col-b">';
$order_detail = getorderlist(base64_decode($_GET['oid']));
if(!empty($order_detail)){
$bill_detail = getbilling(base64_decode($_GET['oid']));
echo '<table class="table table-hover table-bordered">
<thead>
<tr>
<td class="trstep2">ลำดับ</td>
<td>รายการ</td>
<td>จำนวน</td>
<td class="trstep2">หน่วย</td>
<td>ราคา</td>
</tr>
</thead>
<tbody>';
$line = 0;
$cost = 0;
generatemodal();
foreach ($order_detail as $value) {
# code...
$line++;
echo "<tr>";
echo "<td class=\"trstep2\">{$line}</td>";
echo "<td>".getprod_name($value['prod_id'])."</td>";
echo "<td>".$value['prod_value']."</td>";
echo "<td class=\"trstep2\">".getprod_unit($value['prod_id'])."</td>";
echo "<td>".$value['cost']."</td>";
$cost = $cost+(int)($value['cost']);
}
echo "</tbody></table>";
}
echo '</div>
</div>
<div class="row">
<div class="col-a"></div>
<div class="col-b">จำนวน '.$line.' รายการ เป็นเงิน <input type="hidden" name="billcost" value="'.$cost.'">'.$cost.' บาท</div>
</div>
<div class="row">
<div class="col-a"></div>
<div class="col-b">';
$pay_value = 0;
foreach ($bill_detail as $value) { //บรรทัดนี้
# code...
$pay_value = $pay_value+$value['pay'];
}
if($pay_value < $cost){
$dep_value = $cost - $pay_value;
if(!userlevel(base64_decode($_SESSION['ses01']))['club_type'] == 0){
// $payment = 'หลักฐานการชำระเงิน<input id="pupload" name="pupload" type="file" class="form-control"><br>';
//}
//else{
$payment = 'ชำระเพิ่ม <input type="number" name="pbillpayment"> บาท';
}
}
else{
$dep_value = 0;
$payment = '';
}
echo '<p id="billpay">ชำระแล้ว '.$pay_value.' บาท</p><input type="hidden" id="pbillpay" name="pbillpay" value="'.$pay_value.'">
<p id="billdep">ค้างชำระ '.$dep_value.' บาท</p>
</div>
</div>
<div class="row">
<div class="col-a"></div>
<div class="col-b">'.@$payment.'</div>
</div>
<div class="row">
<div class="col-a"></div>
<div class="col-b">';
if($data['book_start'] > time() && $data['book_stop'] > time()){
if(!userlevel(base64_decode($_SESSION['ses01']))['club_type'] == 0){
echo '<button type="submit" id="submitbtn" name="submitbtn" class="btn btn-block btn-success" value="billorder">ตกลง</button>';
}
}
echo '<a href="page.order.php" class="btn btn-block btn-danger">ยกเลิก</a><input type="hidden" name="formfor" value="แก้ไขคำสั่งซื้อ"><input type="hidden" id="token" name="token" value="'.gettoken().'">
</div>
</div>';
}
}
echo '</div>
</div>
<div id="footdiv">
</div>';
htmlcontent('#sidebar',userdetail(getprofile(base64_decode($_SESSION['ses01']))));
}
else{
header('location: action.order.php?error=3');
die();
}
?>
Tag : PHP
|
|
|
|
|
|
Date :
2018-07-01 13:45:16 |
By :
toi2539 |
View :
606 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($bill_detail as $value) { //บรรทัดนี้
นี้ครับ ที่คิดปัญหา
Invalid argument supplied for foreach() in
|
ประวัติการแก้ไข 2018-07-01 13:51:44
|
|
|
|
Date :
2018-07-01 13:46:14 |
By :
toi2539 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองตรวจสอบดูครับ ว่าตัวแปล $bill_detail มีค่าข้อมูลหรือเปล่า
if(count($bill_detail)>0){
foreach ($bill_detail as $value){
............
}
}
ลองดูครับ
|
|
|
|
|
Date :
2018-07-08 01:39:13 |
By :
knzkidz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|