 |
ขอสอบถามเรื่องการทำรายงานสรุปในแต่ละเดือนหน่อยค่ะ..... |
|
 |
|
|
 |
 |
|
ไม่ต้องสร้างเพิ่มก็ได้ครับ นับเอาจากตารางนั้นเลย
ถ้าจะนับจำนวนตามคน ก็ GROUP by คน หรือจะนับแยกตามอะไรบ้างก็จัดกลุ่มตามนั้น
ลองค้นหา COUNT GROUP BY ดูนะครับ
|
 |
 |
 |
 |
Date :
2013-11-24 13:53:30 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูพวก DATE_FORMAT ครับ ทำได้ไม่ยาก
SQL MYSQL DATE_FORMAT
|
 |
 |
 |
 |
Date :
2013-11-24 14:12:58 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ติดตรงเลือกเดือนกับปีอ่ะค่ะ ไม่รู้ว่าจะต้องใส่โค้ดยังไง
ตอนนี้ยังกำหนดให้แสดงได้แค่เดือน 11 แต่อยากให้ค้นหาได้ทุกเดือน แล้วก็ปีด้วยค่ะ
ขอบคุณมากค่ะ
Code (PHP)
<?php require_once('Connections/myconnection.php');
include("session.php");
include("header.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_myconnection, $myconnection);
$query_Recordset1 = "SELECT service_fix FROM service";
$Recordset1 = mysql_query($query_Recordset1, $myconnection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>Untitled Document</title>
</head>
<body>
<center>
<p> </p>
<p> </p>
<p> </p>
<p><h3>รายงานสรุปการแจ้งซ่อม</h3></p>
<p>ค้นหา :
<select name="Month" id="Month">
<option value="">---เลือกเดือน---</option>
<option value="01"><? if($Month=='01') echo " selected='selected'" ?> มกราคม</option>
<option value="02"><? if($Month=='02') echo " selected='selected'" ?> กุมภาพันธ์</option>
<option value="03"><? if($Month=='03') echo " selected='selected'" ?> มีนาคม</option>
<option value="04"><? if($Month=='04') echo " selected='selected'" ?> เมษายน</option>
<option value="05"><? if($Month=='05') echo " selected='selected'" ?> พฤษภาคม</option>
<option value="06"><? if($Month=='06') echo " selected='selected'" ?> มิถุนายน</option>
<option value="07"><? if($Month=='07') echo " selected='selected'" ?> กรกฎาคม</option>
<option value="08"><? if($Month=='08') echo " selected='selected'" ?> สิงหาคม</option>
<option value="09"><? if($Month=='09') echo " selected='selected'" ?> กันยายน</option>
<option value="10"><? if($Month=='10') echo " selected='selected'" ?> ตุลาคม</option>
<option value="11"><? if($Month=='11') echo " selected='selected'" ?> พฤศจิกายน</option>
<option value="12"><? if($Month=='12') echo " selected='selected'" ?> ธันวาคม</option>
</select>
<?php
echo (" ");?>
<select name="Year" id="Year">
<option value="">---เลือกปี---</option>
<option value="2014">2557</option>
<option value="2013">2556</option>
</select>
<input type="submit" name="Submit" value="ค้นหา" />
</p>
<p> </p>
</center>
<center><table width="337" align="center">
<tr>
<td align="center" bgcolor="#999999">บริการที่เข้ารับ</td>
<td align="center" bgcolor="#999999">จำนวนครั้งที่แจ้งซ่อม</td>
</tr>
<?php do { ?>
<tr>
<td align="center" bgcolor="#CCCCCC"><?php echo $row_Recordset1['service_fix']; ?></td>
<?php
$sql = "SELECT ctm_fix,count(ctm_id) AS countID FROM `data_customers` WHERE month(ctm_date) = '11' AND ctm_fix = '".$row_Recordset1['service_fix']."' AND User_add='".$_SESSION['UserID']."'";
$dbquery = mysql_query($sql);
$result = mysql_fetch_array($dbquery);
?>
<td align="center" bgcolor="#CCCCCC"><?php echo $result['countID'];?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</center>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
|
 |
 |
 |
 |
Date :
2013-11-27 10:23:59 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดี๋ยวให้น้อยอ้อยพาทำ บรรทัด 098 -101 ปรับเป็น
<?PHP
if ($_POST[Month'']&&$_POST[Year'']) {
$date_y=$_POST['Year'];
$date_m=$_POST['Month'];
$date_start = $date_y."-".$date_m."-01";
$date_end = $date_y."-".$date_m."-31";
$Sora_AOI="ctm_date BETWEEN '$date_start' AND '$date_end'";
}
$sql = "SELECT ctm_fix,count(ctm_id) AS countID FROM `data_customers` WHERE $Sora_AOI AND ctm_fix = '".$row_Recordset1['service_fix']."' AND User_add='".$_SESSION['UserID']."'";
$dbquery = mysql_query($sql);
$result = mysql_fetch_array($dbquery);
?>
|
 |
 |
 |
 |
Date :
2013-11-27 11:31:07 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้นแบบนี้อ่ะค่ะ
Notice: Undefined index: Month in C:\xampp\htdocs\add-data-customers\report.php on line 98
Notice: Undefined variable: Sora_AOI in C:\xampp\htdocs\add-data-customers\report.php on line 106
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 108
Notice: Undefined index: Month in C:\xampp\htdocs\add-data-customers\report.php on line 98
Notice: Undefined variable: Sora_AOI in C:\xampp\htdocs\add-data-customers\report.php on line 106
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 108
Notice: Undefined index: Month in C:\xampp\htdocs\add-data-customers\report.php on line 98
Notice: Undefined variable: Sora_AOI in C:\xampp\htdocs\add-data-customers\report.php on line 106
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 108
|
 |
 |
 |
 |
Date :
2013-11-27 11:39:37 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กรรม เขียนอักขระยันต์ให้ผิด เครื่องหมายผิดที่ผิดทางพลากอย่างไม่น่าเชื่อ if ($_POST[Month'']&&$_POST[Year''])
แบบนี้นะครับเอาใหม่098-101
<?PHP
if ($_POST['Month']&&$_POST['Year']) {
$date_y=$_POST['Year'];
$date_m=$_POST['Month'];
$date_start = $date_y."-".$date_m."-01";
$date_end = $date_y."-".$date_m."-31";
$Sora_AOI="ctm_date BETWEEN '$date_start' AND '$date_end'";
}
$sql = "SELECT ctm_fix,count(ctm_id) AS countID FROM `data_customers` WHERE $Sora_AOI AND ctm_fix = '".$row_Recordset1['service_fix']."' AND User_add='".$_SESSION['UserID']."'";
$dbquery = mysql_query($sql);
$result = mysql_fetch_array($dbquery);
?>
|
ประวัติการแก้ไข 2013-11-27 11:44:39
 |
 |
 |
 |
Date :
2013-11-27 11:43:28 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนแรกก็แก้เป็นแบบนี้ if ($_POST['Month']&&$_POST['Year']) แล้วค่ะ
ก็ยังไม่ได้อ่ะค่ะ
|
 |
 |
 |
 |
Date :
2013-11-27 11:46:53 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดี๋ยวขอทำความเข้าใจก่อน
1. ctm_date เก็บอะไรไว้ครับ yyyy-mm-dd หรือไม่ 
2. บรรทัด 037คิวรี่อะไร -->$query_Recordset1 = "SELECT service_fix FROM service";   
3. $row_Recordset1['service_fix'] อันนี้มันมาจากคิวรี่บรรทัด 37 ไช่ไหม ? ทำใมลอยมายังงี้ service_fix เก็บอะไรไว้เอ่ย
|
ประวัติการแก้ไข 2013-11-27 11:57:43 2013-11-27 11:59:17
 |
 |
 |
 |
Date :
2013-11-27 11:51:14 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1.ctm_date เก็บวันที่ ที่ได้เพิ่มข้อมูลลงไปค่ะ(วันที่มาซ่อม)

2. เป็นการดึงชื่อ case ที่มีอยู่มาใส่ในตารางคะ

3. service_fix เก็บชื่อ case แต่ละ case ค่ะ ตามรูปข้อ 2.
|
 |
 |
 |
 |
Date :
2013-11-27 11:57:10 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาเจ้า $row_Recordset1['service_fix'] ออกไปก่อนดู เพราะขี้เกียจไล่โค้ด อิอิเอาแยกวันเดือนปีให้ได้ก่อน
Code (PHP)
<?PHP
if ($_POST['Month']&&$_POST['Year']) {
$date_y=$_POST['Year'];
$date_m=$_POST['Month'];
$date_start = $date_y."-".$date_m."-01";
$date_end = $date_y."-".$date_m."-31";
$Sora_AOI="(ctm_date BETWEEN '$date_start' AND '$date_end')";
}
$sql = "SELECT ctm_fix,count(ctm_id) AS countID FROM `data_customers` WHERE $Sora_AOI AND User_add='".$_SESSION['UserID']."' ";
$dbquery = mysql_query($sql);
$result = mysql_fetch_array($dbquery);
?>
|
ประวัติการแก้ไข 2013-11-27 12:02:40 2013-11-27 12:03:10
 |
 |
 |
 |
Date :
2013-11-27 11:58:58 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาออกแล้ว
เหมือนว่าจะเออเร่อเหมือนเดิมค่ะ
Notice: Undefined index: Month in C:\xampp\htdocs\add-data-customers\report.php on line 98
Notice: Undefined variable: Sora_AOI in C:\xampp\htdocs\add-data-customers\report.php on line 106
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 108
Notice: Undefined index: Month in C:\xampp\htdocs\add-data-customers\report.php on line 98
Notice: Undefined variable: Sora_AOI in C:\xampp\htdocs\add-data-customers\report.php on line 106
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 108
Notice: Undefined index: Month in C:\xampp\htdocs\add-data-customers\report.php on line 98
Notice: Undefined variable: Sora_AOI in C:\xampp\htdocs\add-data-customers\report.php on line 106
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 108
|
 |
 |
 |
 |
Date :
2013-11-27 12:02:25 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าไม่ได้อีกนะแสดงว่า
"SELECT ctm_fix,count(ctm_id) AS countID FROM `data_customers`
เจ้า ctm_date ไม่โดน SELECT รึเปล่านะลองปรับเป็น 
$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM `data_customers` WHERE $Sora_AOI AND User_add='".$_SESSION['UserID']."' ";
|
 |
 |
 |
 |
Date :
2013-11-27 12:03:29 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (SQL)
where month(ctm_date) = {$_POST[m]} and year(ctm_date) = {$_POST[y]}
|
 |
 |
 |
 |
Date :
2013-11-27 12:05:25 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ค่ะ ขึ้นเหมือนเดิมเลย TT
|
 |
 |
 |
 |
Date :
2013-11-27 12:07:44 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ให้เอาไปปรับนะครับ ไม่ได้ให้ใช้ทั้งดุ้น ไปเขียนแบบไหนไว้
|
 |
 |
 |
 |
Date :
2013-11-27 12:09:13 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เครียดเลย นี่มันอะไรกัน เราก็ไม่น่าจะผิดพลาดนี่นา   
เอางี้ครับปรับคืนสู่สามัญ เอาเดือนนี้หละยังไม่สนใจค่าที่กล่องกรอกมา ลองดูสิมันออกไหม . . .
$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM data_customers WHERE ctm_date BETWEEN '2013-11-01' AND '2013-11-31' ";
|
 |
 |
 |
 |
Date :
2013-11-27 12:11:46 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้นค่ะ

|
 |
 |
 |
 |
Date :
2013-11-27 12:20:23 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาต่อเลยทีละขั้น
$Sora_AOI="ctm_date BETWEEN '2013-11-01' AND '2013-11-31'";
$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM data_customers WHERE $Sora_AOI ";
ยังงี้ขึ้นไหม
|
 |
 |
 |
 |
Date :
2013-11-27 12:25:22 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้นค่ะ ๆ
|
 |
 |
 |
 |
Date :
2013-11-27 12:30:02 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังงี้หละ. .
Code (PHP)
$date_start ="2013-11-01";
$date_end = "2013-11-31";
$Sora_AOI="ctm_date BETWEEN '$date_start' AND '$date_end'";
$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM data_customers WHERE $Sora_AOI AND User_add='".$_SESSION['UserID']."' ";
ปล. อย่าลืม login ก่อนนะเพราะมีการเช็ค$_SESSION['UserID'] ด้วย
|
ประวัติการแก้ไข 2013-11-27 12:36:11
 |
 |
 |
 |
Date :
2013-11-27 12:34:54 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้นค่ะ

|
 |
 |
 |
 |
Date :
2013-11-27 12:38:02 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต่อๆ ขึ้นไหม ทีนี้ไปเลือกปีเดือนมา. . . .
if ($_POST) {
$date_y=$_POST['Year'];
$date_m=$_POST['Month'];
$date_start = $date_y."-".$date_m."-01";
$date_end = $date_y."-".$date_m."-31";
$Sora_AOI="ctm_date BETWEEN '$date_start' AND '$date_end'";
}else { $Sora_AOI = ""; }
$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM data_customers WHERE $Sora_AOI AND User_add='".$_SESSION['UserID']."' ";
|
ประวัติการแก้ไข 2013-11-27 12:43:12
 |
 |
 |
 |
Date :
2013-11-27 12:42:38 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
error ค่ะ
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 111
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 111
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add-data-customers\report.php on line 111
Code (PHP)
<?php require_once('Connections/myconnection.php');
include("session.php");
include("header.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_myconnection, $myconnection);
$query_Recordset1 = "SELECT service_fix FROM service";
$Recordset1 = mysql_query($query_Recordset1, $myconnection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>Untitled Document</title>
</head>
<body>
<center>
<p> </p>
<p> </p>
<p> </p>
<p><h3>รายงานสรุปการแจ้งซ่อม</h3></p>
<p>ค้นหา :
<select name="Month" id="Month">
<option value="">---เลือกเดือน---</option>
<option value="01"><? if($Month=='01') echo " selected='selected'" ?> มกราคม</option>
<option value="02"><? if($Month=='02') echo " selected='selected'" ?> กุมภาพันธ์</option>
<option value="03"><? if($Month=='03') echo " selected='selected'" ?> มีนาคม</option>
<option value="04"><? if($Month=='04') echo " selected='selected'" ?> เมษายน</option>
<option value="05"><? if($Month=='05') echo " selected='selected'" ?> พฤษภาคม</option>
<option value="06"><? if($Month=='06') echo " selected='selected'" ?> มิถุนายน</option>
<option value="07"><? if($Month=='07') echo " selected='selected'" ?> กรกฎาคม</option>
<option value="08"><? if($Month=='08') echo " selected='selected'" ?> สิงหาคม</option>
<option value="09"><? if($Month=='09') echo " selected='selected'" ?> กันยายน</option>
<option value="10"><? if($Month=='10') echo " selected='selected'" ?> ตุลาคม</option>
<option value="11"><? if($Month=='11') echo " selected='selected'" ?> พฤศจิกายน</option>
<option value="12"><? if($Month=='12') echo " selected='selected'" ?> ธันวาคม</option>
</select>
<?php
echo (" ");?>
<select name="Year" id="Year">
<option value="">---เลือกปี---</option>
<option value="2014">2557</option>
<option value="2013">2556</option>
</select>
<input type="submit" name="Submit" value="ค้นหา" />
</p>
<p> </p>
</center>
<center><table width="337" align="center">
<tr>
<td align="center" bgcolor="#999999">บริการที่เข้ารับ</td>
<td align="center" bgcolor="#999999">จำนวนครั้งที่แจ้งซ่อม</td>
</tr>
<?php do { ?>
<tr>
<td align="center" bgcolor="#CCCCCC"><?php echo $row_Recordset1['service_fix']; ?></td>
<?php
if ($_POST) {
$date_y=$_POST['Year'];
$date_m=$_POST['Month'];
$date_start = $date_y."-".$date_m."-01";
$date_end = $date_y."-".$date_m."-31";
$Sora_AOI="ctm_date BETWEEN '$date_start' AND '$date_end'";
}else { $Sora_AOI = ""; }
$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM data_customers WHERE $Sora_AOI AND User_add='".$_SESSION['UserID']."' ";
$dbquery = mysql_query($sql);
$result = mysql_fetch_array($dbquery);
?>
<td align="center" bgcolor="#CCCCCC"><?php echo $result['countID'];?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</center>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
|
ประวัติการแก้ไข 2013-11-27 12:47:38
 |
 |
 |
 |
Date :
2013-11-27 12:46:13 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
count ไม่ group หน่อยหรอ 
|
 |
 |
 |
 |
Date :
2013-11-27 12:47:04 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
echo $date_start และั $date_end ให้ดูหน่อยครับ เมื่อมีการกรอกเข้ามา
Code (PHP)
if ($_POST) {
$date_y=$_POST['Year'];
$date_m=$_POST['Month'];
$date_start = $date_y."-".$date_m."-01";
$date_end = $date_y."-".$date_m."-31";
$Sora_AOI="ctm_date BETWEEN '$date_start' AND '$date_end'";
}else { $Sora_AOI = ""; }
echo $date_start,$date_end ;
echo $Sora_AOI ;
//$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM data_customers WHERE $Sora_AOI AND User_add='".$_SESSION['UserID']."' ";
|
ประวัติการแก้ไข 2013-11-27 12:55:40
 |
 |
 |
 |
Date :
2013-11-27 12:54:29 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
sadaskldasklkldjklj รู้แล้ววววววววววววววววว 5 55 5 5 5 5      
เมื่อไม่มี SORA AOI โค้ดเราจะอ่านว่า WHERE AND User_add='".$_SESSION['UserID']."' ";
ซึ่งมนผิดหลักการ ทีนี้เอา AND เสียบเข้ามาในน้อง SORA AOI
Code (PHP)
if ($_POST) {
$date_y=$_POST['Year'];
$date_m=$_POST['Month'];
$date_start = $date_y."-".$date_m."-01";
$date_end = $date_y."-".$date_m."-31";
$Sora_AOI="ctm_date BETWEEN '$date_start' AND '$date_end' AND";
}else { $Sora_AOI = ""; }
$sql = "SELECT ctm_date,ctm_fix,count(ctm_id) AS countID FROM data_customers WHERE $Sora_AOI User_add='".$_SESSION['UserID']."' ";
|
ประวัติการแก้ไข 2013-11-27 12:59:11
 |
 |
 |
 |
Date :
2013-11-27 12:58:31 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้นแล้วค่ะ แต่มันยังไม่ได้แบ่งเป็น case

|
 |
 |
 |
 |
Date :
2013-11-27 13:01:42 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็เอาเคสมาใส่สิค่ะ อันที่คิวรี่ไว้นั่นหนะ   
|
 |
 |
 |
 |
Date :
2013-11-27 13:03:36 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จริงๆ แค่ join แล้ว query ครั้งเดียวก็ได้แล้วนะ
|
 |
 |
 |
 |
Date :
2013-11-27 13:08:24 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วค่ะ
ขอบคุณ คุณ meannerss มากๆเลยค่ะ ^^
|
 |
 |
 |
 |
Date :
2013-11-27 13:13:59 |
By :
aorplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาการไล่แบบนี้ไปใช้ได้กับทุกคิวรีครับ ถ้าคิวรี่อะไรแล้วมันเกิดปัญหาเราต้องแก้จากโค้ดพื้นฐานที่สุดก่อน คือ
1. การยัดตัวแปรลงไปตรงๆ ถ้าคิวรี่ได้แล้ว
2. จากนั้นค่อยนำมาแยกชิ้นส่วนว่าตัวไหนคือ โครงสร้างภาษาSQL ตัวไหนคือตัวแปรที่ต้องนำเข้ามา
3. ค่อยๆปรับไปทีละตัวสองตัว แล้วจะพบทางออกในทุกๆคิวรี่ครับ 
อ่ออีกสาเหตุหลักๆเลยที่ผมเลือกแยก $Sora_AOI ไว้โดดเลยๆเมื่อนำไปคืวรี่. .. . ก็เพื่อมีการสร้างฟอร์มคิวรี่วันโดนปีเมื่อไร( ซึ่งมันมักจะเกิดบ่อยๆ ) เราก็แค่ยกเงื่อนใขนี้ไปวางไว้ และเอา $SORA_AOI แทรกเข้าไปในโค้ด SQL สั้นๆจบเป็นอันว่าเราสามารถทำคิวรี่ตามเดือนได้อย่างง่ายดายแล้วในทุกๆฟอร์ม  

|
ประวัติการแก้ไข 2013-11-27 13:30:46
 |
 |
 |
 |
Date :
2013-11-27 13:22:55 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ติดใจ Sora aoi จริง ๆ .....
|
 |
 |
 |
 |
Date :
2013-11-27 13:40:50 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|