|
 |
|
สอบถามการดึงข้อมูลจาก database ออกมาโชว์ ถ้าต้องการนำเงื่อนไขเอามาโชว์เฉพาะเดือน ตุลาคม formate วันที่เป็นแบบนี้ |
|
 |
|
|
 |
 |
|
ลองแบบนี้ครับ
Code (PHP)
$strSQL = "SELECT * FROM xxxxx where substr(date,6,2) = '10'
|
 |
 |
 |
 |
Date :
2009-11-07 21:51:11 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วถ้าผมใช้ชื่อ ฟิวส์ที่เก็บข้อมูลวันที่ submissiondate ต้องเปี่ยนตรงไหนอ่ะครับ
แล้ว substr และ (date,6,2) คืออะไรอ่ะครับ
|
 |
 |
 |
 |
Date :
2009-11-07 22:04:34 |
By :
evekrub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
substr(date,6,2) เลือกเอา สติงในข้อความ ในตำแหน่งที่ 6 จำนวน 2 ตำแหน่งครับ
เช่น
ตำแหน่ง--- | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
วันเดือนปี | 2 | 0 | 0 | 9 | -- | 1 | 0 | -- | 0 | 1
=| 1 | 0 |
Code (PHP)
$strSQL = "SELECT * FROM xxxxx where substr(submissiondate,6,2) = '10'
|
 |
 |
 |
 |
Date :
2009-11-07 22:37:05 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$strSQL = "SELECT * FROM xxxxx where date = '2009-10-01';
ถ้าเลือกเฉพาะเดือน
$strSQL = "SELECT * FROM xxxxx where month(date) = '10';
ไม่เห็นต้องไปตัดสตริงให้ยุ่งยากเลยครับ
|
 |
 |
 |
 |
Date :
2009-11-08 00:18:21 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้แล้วแต่ครับ ถ้าหากเก็บเป็น vachar ไม่ใช่ date ก็ อาจต้องใช้ครับ
ผมตัดสติงเอา เพราะว่าถ้าหากเป็น date เวลาที่ export ออกมาเป็น excell ที่จะทำรายงานส่งเจอปัญหาเรื่องรูปแบบ บ่อยครับ จะออกเป็น รูปแบบ ที่เราไม่สามารถรายงานข้อมูลได้ครับ ถ้าใครเคยใช้ excell คงเคยเจอแบบผมบ้าง ซึ่งเวลาที่รายงานให้ กพร เขาจะเอาเป็น vachar จำนวน 10 หลัก โดยกำหนดรูปแบบเป็น 10/20/2552 เป็นต้นครับ
ผมเลยต้องใช้ ตัดสติงเอาครับ ส่วนท่านอื่นจะใช้ยังไง ขึ้นอยู่กับการนำไปประยุกต์ครับ
ผมขอขอบคุณ คุณ deawx มากครับ ผมเองก็ไม่เคยใช้ที่แนะนำมาครับ เป็นความรู้ใหม่ให้ผมอีกแล้ว
|
 |
 |
 |
 |
Date :
2009-11-08 00:32:05 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก็บเป็น varchar เวลาจะเอาไปเปรียบเทียบหรือเลือกช่วงเวลา จะลำบากครับ ถ้าเจอปัญหา excell date_format น่าจะช่วยได้
|
 |
 |
 |
 |
Date :
2009-11-08 00:50:11 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่วนใหญ่ที่ผมใช้จะไม่ค่อยมีการคำนวน วันที่ครับ แต่จะเป็นการ ค้นหาข้อมูลซะเป็นส่วนใหญ่ครับ เลยไม่ค่อบ ซีเรียด เรื่อง format ครับ
|
 |
 |
 |
 |
Date :
2009-11-08 07:51:23 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้น errorr ตามนี้เลยอ่ะครับ
Code (PHP)
Error Query [SELECT * FROM submission where type = '01' and agent = 'xxxx' month(submissiondate) ='10'; order by submissiondate ]
|
 |
 |
 |
 |
Date :
2009-11-08 08:35:03 |
By :
evekrub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
Error Query [SELECT * FROM submission where type = '01' and agent = 'xxxx' and month(submissiondate) ='10' order by submissiondate ]
ตก and ไปตัวหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2009-11-08 08:43:52 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
SELECT * FROM submission where type = '01' AND agent = 'xxxx' AND month(submissiondate) ='10' ;
อันนี้ไม่ต้องไปจัดเรียงตาาม submissiondate เลยครับ เพราะมันมีแค่ เดือนเดียวที่เราเลือก
deawx
[email protected]
ปรึกษา php ฟรีจ้า
|
 |
 |
 |
 |
Date :
2009-11-08 10:14:51 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|