|
 |
|
ผมต้องการออกรายงาน แยกว่า a มีเท่าไร, b มีเท่าไร,c มีเท่าไร ,d มีเท่าไร query แสดงออกมามันไม่ตรงกับที่เรา group by ไว้ |
|
 |
|
|
 |
 |
|
ผมต้องการออกรายงาน แยกว่า a มีเท่าไร, b มีเท่าไร,c มีเท่าไร ,d มีเท่าไร query แสดงออกมามันไม่ตรงกับที่เรา group by ไว้
แต่ตอนที่ผม query จาก คำสั่ง sql ออกมาค่าได้ตรง พอใช้ php เขียน ค่าที่ต้องการไม่ตรงซะงั้น ไม่ทราบว่า code ที่เขียนด้วย php
ของผมผิดหรือเปล่าครับ ช่วยชี้แนะหน่อยครับ
ขอบคุณครับ
รูป ข้อมูลใน ฐานข้อมูลที่ต้องการ query

รูป แสดงตอน query ออกมาข้อมูลไม่ตรง เขียนจาก php

รูป query จาก คำสั่ง mysql ออกมาเป็นค่าทีถูกต้อง

code php ที่เขียน แสดงรายงาน แสดงค่าไม่ถูกต้อง
Code (PHP)
<?
function HeaderingExcel($filename) {
header("Content-type: application/vnd.ms-excel");
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header("Content-Disposition: attachment; filename=$filename" );
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
}
function HeaderingPDF($filename) {
header("Content-type: application/pdf");
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header("Content-Disposition: attachment; filename=$filename" );
}
error_reporting(E_ALL ^ E_NOTICE);
if ($exp == "XLS") {
HeaderingExcel("reportmonth.xls");
}
if ($exp == "PDF") {
HeaderingPDF("reportmonth.pdf");
}
?>
<?php $monthname=array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");?>
<? $day =array("วันจันทร์","วันอังคาร","วันพุธ","วันพฤหัส","วันศุกร์","วันเสาร์","วันอาทิตย์"); ?>
<?
list($day1, $month1, $year1) = split('[/.-]', $daymonthyear1);
$year1 = $year1 - 543;
$daymonthyear1= "$year1-$month1-$day1";
list($day2, $month2, $year2) = split('[/.-]', $daymonthyear2);
$year2 = $year2 - 543;
$daymonthyear2= "$year2-$month2-$day2";
?>
<?php
//include "config.php";
?>
<HTML>
<HEAD>
<TITLE>reportgroup</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<?
if ($exp == "HTML") {
echo "<LINK REL='StyleSheet' HREF='../../html/css/style.css' TYPE='text/css'>";
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<style type="text/css">
<!--
.unnamed1 {
font-family: "Tahoma", Tahoma, sans-serif;
font-size: 12px;
}
-->
</style>
<link href="fileinclude/stylesheet.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style2 {font-family: "ms Sans Serif"}
-->
</style>
<link href="css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style3 {font-size: 12px}
-->
</style>
</HEAD>
<BODY topmargin="0" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> </tr>
</table>
<?
$yearsql = $sel1_year - 543;
//echo"$yearsql";
?>
<div align="center" class="unnamed1">
<span class="style2">
<? if ($month1== '1') { $showmonth1 = 'มกราคม' ;}
if ($month1== '2') { $showmonth1 = 'กุมภาพันธ์' ;}
if ($month1== '3') { $showmonth1 = 'มีนาคม' ;}
if ($month1== '4') { $showmonth1 = 'เมษายน' ;}
if ($month1== '5') { $showmonth1 = 'พฤษภาคม' ;}
if ($month1== '6') { $showmonth1 = 'มิถุนายน' ;}
if ($month1== '7') { $showmonth1 = 'กรกฏาคม' ;}
if ($month1== '8') { $showmonth1 = 'สิงหาคม' ;}
if ($month1== '9') { $showmonth1 = 'กันยายน' ;}
if ($month1== '10') { $showmonth1 = 'ตุลาคม' ;}
if ($month1== '11') { $showmonth1 = 'พฤศจิกายน' ;}
if ($month1== '12') { $showmonth1 = 'ธันวาคม' ;}
if ($month2== '1') { $showmonth2 = 'มกราคม' ;}
if ($month2== '2') { $showmonth2 = 'กุมภาพันธ์' ;}
if ($month2== '3') { $showmonth2 = 'มีนาคม' ;}
if ($month2== '4') { $showmonth2 = 'เมษายน' ;}
if ($month2== '5') { $showmonth2 = 'พฤษภาคม' ;}
if ($month2== '6') { $showmonth2 = 'มิถุนายน' ;}
if ($month2== '7') { $showmonth2 = 'กรกฏาคม' ;}
if ($month2== '8') { $showmonth2 = 'สิงหาคม' ;}
if ($month2== '9') { $showmonth2 = 'กันยายน' ;}
if ($month2== '10') { $showmonth2 = 'ตุลาคม' ;}
if ($month2== '11') { $showmonth2 = 'พฤศจิกายน' ;}
if ($month2== '12') { $showmonth2 = 'ธันวาคม' ;}
$showyear1 = $year1+543;
$showyear2 = $year2+543;
?>
</span>
<p class="unnamed1"><span class="style2"><strong> <br>
<br>
รายงานวิศวกรรมความปลอดภัยและสภาพแวดล้อมในโรงพยาบาล<br><br>
ระหว่างวันที่ <? echo "$day1 $showmonth1 $showyear1" ?> ถึงวันที่ <strong><? echo "$day2 $showmonth2 $showyear2" ?></strong></strong></span><br>
<br>
<strong><br>
</strong><br>
<table width="447" border="1" cellpadding="0" cellspacing="0" bordercolordark="#FFFFFF">
<tr bgcolor="#FFA4FF" class="unnamed1">
<td width="268" height="20" bgcolor="#00CC99"><div align="center" class="style2">ระดับความไม่ปลอดภัย</div></td>
<td width="173" bgcolor="#00CC99"><div align="center" class="style2">จำนวนครั้ง</div></td>
<tr bgcolor="" class="unnamed1">
<?
include("config.php");
$sql="SELECT s1,secur_name ,count(s1)
FROM secur_data WHERE date BETWEEN '$daymonthyear1' AND '$daymonthyear2'
GROUP BY s1";
$dbquery = mysql_db_query($dbname, $sql);
while($fet=mysql_fetch_array($dbquery)){
$s1= $fet['s1'];
$secur_name = $fet['secur_name'];
?>
<td class="unnamed1"><span class="style2 style3"><? echo"$secur_name";?></span></td>
<td class="unnamed1 style2 style3" ><center><? echo"$s1";?></center></td>
</tr>
<?
}
?>
<tr class="unnamed1">
</table>
<br>
<br>
<br>
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php $monthname=array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");?>
<? $day =array("วันจันทร์","วันอังคาร","วันพุธ","วันพฤหัส","วันศุกร์","วันเสาร์","วันอาทิตย์"); ?>
<td class="unnamed1"><div align="right">วันที่ออกรายงาน : <? echo $day[date('w')-1]." ".date('d')." ". $monthname[date('n')-1]." ".(date('Y')+543)." เวลา ".date('H:i:s');?></div></td>
</tr>
</table>
</div>
</BODY>
</HTML>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-06-17 10:30:22 |
By :
มือใหม่ |
View :
1006 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่านแล้วงง เยอะเกิน
|
 |
 |
 |
 |
Date :
2012-06-18 07:43:49 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|