|
|
|
รบกวนช่วยดูหน่อยครับคิวรีข้อมุลไม่ขึ้นจะต้องเขียนยังไงครับ |
|
|
|
|
|
|
|
Code (PHP)
<?
session_start();
if (session_is_registered("valid_uname") && session_is_registered("valid_pwd")) {
}else{
header('location:index.php');
exit();
}
require_once('connect/connect.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>..:: ระบบจัดการฐานข้อมูล ::</title>
<style type="text/css">
<!--
.style2 {font-family: Tahoma; font-size: 12px; }
.style3 {
font-family: Tahoma;
font-weight: bold;
font-size: 12px;
}
.style4 {font-family: Tahoma}
.style5 {font-size: 12px}
.style6 {background-color: #FFFFFF; font-size: 12px;}
.style7 {color: #000000; cursor: hand; font-weight: normal; font-size: 12px;}
-->
</style>
</head>
<body>
<div align="center">
<table cellspacing="1" cellpadding="4" width="68%" bgcolor="#cccccc" border="0" align="center" height="10">
<tbody>
<tr bgcolor="#e5e5e5">
<td width="100%" bgcolor="#FFFFFF"><div align="center"></div>
<table cellspacing="1" cellpadding="4" width="100%" border="0" align="center" height="10">
<tbody>
<tr bgcolor="#e5e5e5">
<td width="35%" bgcolor="#FFFFFF"><div align="left" class="style3"><img src="../image/allrowto.gif" alt="" width="11" height="11" align="absbottom" /> ดูรายงานรายได้/ ต่อเดือน </div></td>
<td width="22%" align="middle" bgcolor="#FFFFFF"><div align="left"><span class="style4"><span class="style5"></span></span> </div></td>
<td width="43%" bgcolor="#FFFFFF"><div align="right" class="style2"><a href="re_profit.php">กลับไปหน้าหลัก</a></div></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
<table width="68%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><div align="right">
<table cellspacing="1" cellpadding="4" width="93%" bgcolor="#FFFFFF" border="0" align="center" height="10">
<tbody>
<tr bgcolor="#e5e5e5">
<form action="" method="post" name="form1" class="bb5" id="form1">
<td width="100%" bgcolor="#FFFFFF"><div align="center"><span class="style2">เลือกวันที่
<select name="dd" id="dd"class="style6">
<option value="01" selected="selected">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
เดือน
<select name="mm" class="style6" id="mm">
<option value="01" selected="selected">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
ปี
<select name="yy" size="1" class="style6" id="yy">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</span><span class="style2">ถึงวันที่
<select name="dd2" id="dd2"class="style6">
<option value="01" selected="selected">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
เดือน
<select name="mm2" class="style6" id="mm2">
<option value="01" selected="selected">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
ปี
<select name="yy2" size="1" class="style6" id="yy2">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
<input name="submit2" type="submit" class="style7" value="ดูรายงาน" />
</span></div></td>
</form>
</tr>
</tbody>
</table>
</div>
<p><span class="style2">
<? if($dd && $mm && $yy && $dd2 && $mm2 && $yy2)
{
$date1 = "$yy-$mm-$dd";
$date2 = "$yy2-$mm2-$dd2";}
//print "$date1 , $date2";
if($date1>$date2)
{
echo "<script>alert('ใส่ข้อมูลวันให้ถูกต้อง');history.back();</script>";
}?>
<?
$sql3 = "select * from payments where pay_date between '$date1' and '$date2' and payments.pay_status='1' group by pay_date order by pay_date asc ";
$query3=mysql_query($sql3,$conn);
while($db1=mysql_fetch_array($query3)){
$date=$db1[pay_date];
?>
</span></p>
<table cellspacing="1" cellpadding="3" width="93%" bgcolor="#CCCCCC" border="0" align="center" height="10">
<tr bgcolor="#e5e5e5">
<td colspan="8" bgcolor="#FFFFFF"><div align="center" class="style2">
<div align="left" class="style2"> วันที่
<?=$date;?>
</div>
</div></td>
</tr>
<tbody>
<tr bgcolor="#e5e5e5">
<td bgcolor="#FFFFFF"><div align="center" class="style2">หมวด</div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2">ชื่อสินค้า</div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2">จำนวน</div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2">ยอดขาย</div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2">ต้นทุน</div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2" >กำไร</div></td>
</tr>
<?
$sql6 = "select orders.or_id,category.ca_name,products.prod_name,products.prod_price,order_detail.quantity,products.prod_cost,sum(order_detail.quantity) as gg from orders inner join payments on (payments.or_id=orders.or_id) inner join order_detail on(orders.or_id=order_detail.or_id) inner join products on (order_detail.prod_id=products.prod_id) inner join category on (products.ca_id=category.ca_id) where payments.pay_date between '$date' and '$date2' and payments.pay_status='1' and payments.pay_date='$date' group by prod_name order by ca_name ";
$query6=mysql_query($sql6,$conn);
$row=mysql_num_rows($query6);
$i=0;
$total1=0;
$total2=0;
$total3=0;
while($i<$row){
$db=mysql_fetch_array($query6);
$ca_name=$db['ca_name'];
$prod_name=$db['prod_name'];
if ($show==$ca_name) { $aaa = "";}else{ $aaa = $ca_name; }
$show=$ca_name;
$tt=$db[gg]*$db[prod_price]-$db[gg]*$db[prod_cost];
$s=$sell=$db[gg]*$db[prod_price];
$cost=$db[gg]*$db[prod_cost];
$total1+=$sell;
$total2+=$cost;
$total3+=$tt;
?> <tr bgcolor="#e5e5e5">
<td width="62" bgcolor="#FFFFFF"><div align="center" class="style2">
<?=$aaa;?>
</div></td>
<td width="201" bgcolor="#FFFFFF"><div align="center" class="style2">
<?=$prod_name;?>
</div></td>
<td width="68" bgcolor="#FFFFFF"><div align="center" class="style2">
<?=$db['gg'];?>
</div></td>
<td width="54" bgcolor="#FFFFFF"><div align="center" class="style2">
<?=number_format($sell,2,'.',',');?>
</div></td>
<td width="49" bgcolor="#FFFFFF"><div align="center" class="style2">
<?=number_format($cost,2,'.',',');?>
</div></td>
<td width="51" bgcolor="#FFFFFF"><div align="center" class="style2">
<?=number_format($tt,2,'.',',');?>
</div></td>
</tr> <? $i++;} ?>
<tr bgcolor="#e5e5e5">
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><div align="center" class="style2">
<div align="right">รวม (บาท) </div>
</div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2"><font color="#FF0000">
<? echo number_format($total1,2,'.',',');?>
</font> </div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2"><font color="#FF0000">
<? echo number_format($total2,2,'.',',');?>
</font> </div></td>
<td bgcolor="#FFFFFF"><div align="center" class="style2"> <font color="#FF0000">
<? echo number_format($total3, 2,'.',',');?>
</font> </div></td>
</tr>
</tbody>
</table>
<? } ?>
<br />
</td>
</tr>
</table>
<br />
<input type="button" value="สั่งพิมพ์หน้านี้.." onclick="javascript:window.print()" name="print" />
</div>
</body>
</html>
ออกทางหน้าจอครับ
สังเกตตารางวันที่ 10 กับ 11 ฟิลล์หมวดจะว่าง ปกติจะต้องขึ้นกรีฑารบกวนช่วยแก้ให้หน่อยครับ
Tag : PHP
|
|
|
|
|
|
Date :
2014-02-25 11:44:36 |
By :
momotaro12 |
View :
631 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คิดว่าปัญหาน่าจะอยู่ที่บรรทัด228-240ครับ
|
|
|
|
|
Date :
2014-02-25 11:48:23 |
By :
momotaro12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ca_name เช็คว่ามีค่าไหม น่ะครับ
|
|
|
|
|
Date :
2014-02-25 11:59:57 |
By :
FreshyMusiC |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จากกระทู้ที่ #NO 106215 และกระทู้นี้
ลองศึกษาดูครับ GROUP BY Grouping Sets
GoodLuck.
|
|
|
|
|
Date :
2014-02-25 12:05:53 |
By :
love9713 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|