|
|
|
ขอสอบถามหน่อบครับ ผม Group by ไม่ได้ อะครับแบบวนลูป พี่ ๆช่วยทีครับ คือชืิ่อเหมือนกันให้รวมกัน |
|
|
|
|
|
|
|
Code (PHP)
<?php
include '../function.inc.php';
include 'chk_sess.php';
$stdate=$_GET['stdate'];
$x='';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $sys_title; ?></title>
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
<link rel="stylesheet" href="../css/font-awesome.min.css">
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="page-header">
<h3>รายงานยอดขายแบ่งตารางเฉพาะวันที่</h3>
<p>ตั้งแต่วันที่ : <?php echo thaidate($_GET['stdate']); ?> ถึงวันที่ : <?php echo thaidate($_GET['endate']); ?></p>
</div>
<?php while (strtotime($stdate) <= strtotime($_GET['endate'])) {
$where=' where orders_date="'.$stdate.'" ';
$query = sprintf('select * from orders %s ',$where);
$result = mysqli_query($con,$query);
if (mysqli_num_rows($result)>0) {
?>
<table class="table table-bordered">
<p>วันที่ : <?php echo thaidate($stdate); ?></p>
<thead>
<tr>
<th>ลำดับ</th>
<th>ชื่อสินค้า</th>
<th>จำนวน</th>
<th>ราคา</th>
<th>รวมเป็นเงิน</th>
</tr>
</thead>
<?php
$sum=0; $sum_total=0;
$query = sprintf('select * from orders %s ',$where);
$result = mysqli_query($con,$query);
if (mysqli_num_rows($result)>0)
{
$val='';
for ($i=1;$i<=mysqli_num_rows($result);$i++) {
$rs = mysqli_fetch_array($result);
$query2 = sprintf('select * from orders_detail where orders_id="%s" group by pro_no ',$rs['orders_id']);
$result2 = mysqli_query($con,$query2);
for ($j=1;$j<=mysqli_num_rows($result2);$j++) {
$rs2 = mysqli_fetch_array($result2);
$query3 = sprintf('select * from product where pro_no="%s" ',$rs2['pro_no']);
$result3 = mysqli_query($con,$query3);
$rs3 = mysqli_fetch_array($result3);
$sum=$rs3['pro_price'] * $rs2['pro_amount'];
$sum_total+=$sum; ?>
<tbody>
<tr>
<td><?php echo $rs3['pro_no']; ?></td>
<td><?php echo $rs3['pro_name']; ?></td>
<td><?php echo $rs2['pro_amount'].' '.$rs3['pro_unit']; ?></td>
<td><?php echo $rs3['pro_price'] ?> บาท</td>
<td>
<?php echo number_format($sum,2); ?> บาท
</td>
<?php
$x +=$rs2['pro_amount'] * $rs3['pro_price'];
$val +=$rs2['pro_amount'] * $rs3['pro_price'];
} }} ?>
</tr>
</tbody>
<tr>
</tr>
<?php } $stdate = date ("Y-m-d", strtotime("+1 day", strtotime($stdate)));}?>
</table>
<?php
$where = ' where orders_date>="'.$_GET['stdate'].'" and orders_date<="'.$_GET['endate'].'" ';
$query = sprintf('select * from orders %s order by orders_id desc',$where);
$result = mysqli_query($con,$query);
if (mysqli_num_rows($result)<=0) {msgbox('ไม่มีข้อมูลที่ค้นหา','report.php');}
else{ $val=0;
for ($i=1;$i<=mysqli_num_rows($result);$i++) {
$rs = mysqli_fetch_array($result);
$sum=0;
$query2 = 'select * from orders_detail where orders_id='.$rs['orders_id'];
$result2 = mysqli_query($con,$query2);
for ($j=1;$j<=mysqli_num_rows($result2);$j++) {
$rs2 = mysqli_fetch_array($result2);
$query3 = 'select * from product where pro_no="'.$rs2['pro_no'].'"';
$result3 = mysqli_query($con,$query3);
$rs3 = mysqli_fetch_array($result3);
$val+=$rs2['pro_amount'] * $rs3['pro_price'];
$sum +=$rs2['pro_amount'] * $rs3['pro_price'];
}
$query4 = sprintf('select * from branch where br_id=%s',$rs['branch_id']);
$result4 = mysqli_query($con,$query4);
$rs4 = mysqli_fetch_array($result4);
?>
<?php } } ?>
<h4 class="text-right">
รวมทั้งหมด <?php echo $i-1; ?> รายการ<br><br>
รวมเงินทั้งสิ้น <?php $t = $x*7/100 ;
$c = $x + $t; echo number_format($x,2);?> บาท
</h4>
<hr>
<p><a href="#" onclick="window.print()"><i class="fa fa-print"></i> พิมพ์</a></p>
</div>
</body>
</html>
ช่วยทีครับข้อสอบบด้วย
Tag : PHP
|
|
|
|
|
|
Date :
2016-10-18 14:28:07 |
By :
DisconnectOver |
View :
641 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo $query2; ไปทดสอบใน phpmyadmin ....
|
|
|
|
|
Date :
2016-10-18 15:07:13 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับผม
|
|
|
|
|
Date :
2016-10-19 10:40:24 |
By :
DisconnectOver |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|