 |
[PHP]
สอบถาม การเขียน ตารางแบบ matrix หน่อยครับ php ระบบขายสินค้าร้านสหกรณ์ |
|
 |
|
|
 |
 |
|
ผมจะคิวรี่มัน3 รอบเลยครับ อ่านแล้วอย่างงนะ เพราะผมก็งงฮาๆๆๆ
Code (PHP)
01. Loop1. WHERE order_date = $ปีที่ต้องการแสดง GROUP BY member_id
02. {
03.
04. Loop2 เอา member id ที่คิวรี่ได้มา loop ต่อว่ามีเดือนอะไรบ้าง ไล่ไปจากเดือน 1
05. {
06. WHERE member_id = ที่คิวรี่มา AND เดือน= $i AND ปี=$ปีที่ต้องการแสดง
07. เปิดTd และแสดงผล ทำไปเรื่อยจน $i >12 ก็ให้หยุด
08. $i ++;
09. }
10.
11. เสร็จลูปก็ได้ 1 คนวนขึ้นไปใหม่และเปิด tr เช็คไปเรื่อยว่ามีคนต่อไปมั้ย
12. $x ++;
13. }
|
 |
 |
 |
 |
Date :
2014-11-16 20:40:08 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
01. $sql ="
02. select
03. m.id, m.name
04. sum(m01.total), sum(m02.total), sum(m03.total), sum(m04.total), sum(m05.total), sum(m06.total),
05. sum(m07.total), sum(m08.total), sum(m09.total), sum(m10.total), sum(m11.total), sum(m12.total)
06. from (
07. select member.id, member.name,
08. '2013-01' z01, '2013-02' z02, '2013-03' z03, '2013-04' z04, '2013-05' z05, '2013-06' z06,
09. '2013-07' z07, '2013-08' z08, '2013-09' z09, '2013-10' z10, '2013-11' z11, '2013-12' z12
10. from member
11. ) as m
12. left join view_order m01 on substring( m01.order_date , 1, 7)=m.z01
13. left join view_order m02 on substring( m02.order_date , 1, 7)=m.z02
14. left join view_order m03 on substring( m03.order_date , 1, 7)=m.z03
15. left join view_order m04 on substring( m04.order_date , 1, 7)=m.z04
16. left join view_order m05 on substring( m05.order_date , 1, 7)=m.z05
17. left join view_order m06 on substring( m06.order_date , 1, 7)=m.z06
18. left join view_order m07 on substring( m07.order_date , 1, 7)=m.z07
19. left join view_order m08 on substring( m08.order_date , 1, 7)=m.z08
20. left join view_order m09 on substring( m09.order_date , 1, 7)=m.z09
21. left join view_order m10 on substring( m10.order_date , 1, 7)=m.z10
22. left join view_order m11 on substring( m11.order_date , 1, 7)=m.z11
23. left join view_order m12 on substring( m12.order_date , 1, 7)=m.z12
24. group by m.id
25. ";
|
 |
 |
 |
 |
Date :
2014-11-16 20:41:59 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ เดี๋ยวผมขอลองก่อนนะครับ
|
 |
 |
 |
 |
Date :
2014-11-16 20:49:25 |
By :
bcmeanzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
left join view_order m01 on substring( m01.order_date , 1, 7)=m.z01
พลาดไปนิด ครับ ลืม m.id=m01.member_id and ใส่ทุกอันนะครับ
left join view_order m01 on m.id=m01.member_id and substring( m01.order_date , 1, 7)=m.z01
|
ประวัติการแก้ไข 2014-11-16 21:06:33
 |
 |
 |
 |
Date :
2014-11-16 21:03:43 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ Chaidhanan ที่มาช่วยครับ อยากจะรบกวนอีกครั้งนึงครับ

คือผม query ออกมาแล้ว ตรง sum มันผิด
แก้ตรงไหน ยังไงครับ
|
 |
 |
 |
 |
Date :
2014-11-17 17:45:04 |
By :
bcmeanzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
วิธีเทสต ครับ
select member_id, total from view_order
where member_id = 'idของคุณสมชาย'
and order_date >'2014-01-01'
order by order_date
|
 |
 |
 |
 |
Date :
2014-11-17 18:09:21 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ของ สมหญิงครับ

เดือน 10 ต้อง 8 บาท แต่เป็น 24
เดือน 11 ถูกแล้ว 170 บาท ครับ
|
 |
 |
 |
 |
Date :
2014-11-17 18:58:09 |
By :
bcmeanzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รูปภาพที่ เอามาให้ ดู อันแรกที่ผิด น่ะครับ สีเขียวคาดเหลือง ใช้โปรแกรมอะไรทำครับ
ลองโค๊ดจาก phpmyadmin ตรงๆ เลยผิดหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2014-11-17 19:09:37 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ mysql front 5.0 ครับ

ผมลอง phpmyadmin เหมือนกันครับ
เหมือนประมาณว่า ซื้อหลายๆชิ้นมัน คูณกันเข้าไปอีก - -"
อย่างของ สมชาย เดือนที่ 9 กับ 10 ซื้อแค่ 8 บาท ถูกต้องแล้วครับ
|
ประวัติการแก้ไข 2014-11-17 19:23:54
 |
 |
 |
 |
Date :
2014-11-17 19:21:45 |
By :
bcmeanzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วย คิวรี่ เอา member_id, order_date กับ total มาให้ลอง หน่อยได้ไหมครับ ของ ซัก 3 id
|
 |
 |
 |
 |
Date :
2014-11-17 19:29:32 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

อันนี้ฐานข้อมูลนะครับ
http://www.system-4x.com/sale_project.zip
รบกวนหน่อยนะครับ
|
 |
 |
 |
 |
Date :
2014-11-17 19:37:19 |
By :
bcmeanzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษครับ โค๊ดเดิมไม่ work ครับ แค่ 1000 รายการ ก็เดี้ยงแล้วครับ
สร้าง วิว ไว้ก่อนครับ แล้ว ค่อยคิวรี่ ที หลัง มันจะ ใช้ tempfile ในการคิวรี่ ถ้าทำแบบ โค๊ดเก่า มัน ทำทุกขั้นตอน
Code (SQL)
1. # Create View
2. CREATE
3. ALGORITHM = UNDEFINED
4. VIEW `member_sum_month`
5. AS SELECT member_id as id, substring (order_date, 1,7) as dte, sum (total) as total
6. FROM `view_order` group by member_id, substring ( order_date, 1, 7)
Code (SQL)
01. select
02. m.id, m. name
03. , m01.total, m02.total, m03.total
04. , m04.total, m05.total, m06.total
05. , m07.total, m08.total, m09.total
06. , m10.total, m11.total, m12.total
07. from (
08. select id , name
09. , '2014-01' z01, '2014-02' z02, '2014-03' z03
10. , '2014-04' z04, '2014-05' z05, '2014-06' z06
11. , '2014-07' z07, '2014-08' z08, '2014-09' z09
12. , '2014-10' z10, '2014-11' z11, '2014-12' z12
13. from member
14. ) as m
15. left join member_sum_month m01 on m01.id=m.id and m01.dte=m.z01
16. left join member_sum_month m02 on m02.id=m.id and m02.dte=m.z02
17. left join member_sum_month m03 on m03.id=m.id and m03.dte=m.z03
18. left join member_sum_month m04 on m04.id=m.id and m04.dte=m.z04
19. left join member_sum_month m05 on m05.id=m.id and m05.dte=m.z05
20. left join member_sum_month m06 on m06.id=m.id and m06.dte=m.z06
21. left join member_sum_month m07 on m07.id=m.id and m07.dte=m.z07
22. left join member_sum_month m08 on m08.id=m.id and m08.dte=m.z08
23. left join member_sum_month m09 on m09.id=m.id and m09.dte=m.z09
24. left join member_sum_month m10 on m10.id=m.id and m10.dte=m.z10
25. left join member_sum_month m11 on m11.id=m.id and m11.dte=m.z11
26. left join member_sum_month m12 on m12.id=m.id and m12.dte=m.z12
27. group by m.id
|
 |
 |
 |
 |
Date :
2014-11-17 21:17:19 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ Chaidhanan อีกครั้งครับ
ได้เรียบร้อยครับ ไว้จะมาถามใหม่ครับ ถ้าติดตรงไหน แหะๆ 
|
 |
 |
 |
 |
Date :
2014-11-17 21:31:54 |
By :
bcmeanzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ข้องใจ โค๊ด เลยเอาไปลอง จนได้ แบบนี้
Code (SQL)
01. select
02. m.id, m. name
03. , sum (total * (od= '2014-01' ) ) Jan
04. , sum (total * (od= '2014-02' ) ) Feb
05. , sum (total * (od= '2014-03' ) ) Mar
06. , sum (total * (od= '2014-04' ) ) Apr
07. , sum (total * (od= '2014-05' ) ) May
08. , sum (total * (od= '2014-06' ) ) Jun
09. , sum (total * (od= '2014-07' ) ) Jul
10. , sum (total * (od= '2014-08' ) ) Aug
11. , sum (total * (od= '2014-09' ) ) Sep
12. , sum (total * (od= '2014-10' ) ) Oct
13. , sum (total * (od= '2014-11' ) ) Nov
14. , sum (total * (od= '2014-12' ) ) ` Dec `
15. from member m
16. left join (
17. select member_id as id, substring ( order_date , 1, 7) od, sum (total) as total
18. from view_order group by member_id, substring ( order_date , 1, 7)
19. ) as vo on vo.id=m.id group by m.id
|
 |
 |
 |
 |
Date :
2014-11-18 10:47:35 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่งมาเห็น สุดยอดครับ ได้เหมือนกัน สั้นกว่าเดิม
ขอบคุณอีกครั้งครับ
|
 |
 |
 |
 |
Date :
2014-11-22 09:17:41 |
By :
bcmeanzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
           Code (PHP)
01. <strong>Code (PHP)</strong>
02. [php]<strong>Code (ASP)</strong>
03. <span class = "notranslate" ><font class = "css_code" ><pre class = "brush:asp" ><strong>Code (ASP)</strong>
04. <div class = "code" ><span class = "notranslate" ><font class = "fontcode" ><strong>Code (VB.NET)</strong>
05. <span class = "notranslate" ><font class = "css_code" ><pre class = "brush:vb" ><strong>Code (VB.NET)</strong>
06. <div class = "code" ><span class = "notranslate" ><font class = "fontcode" ><strong>Code (C#)</strong>
07. <span class = "notranslate" ><font class = "css_code" ></font><pre class = "brush:cs" ><font class = "css_code" ><strong>Code (C#)</strong>
08. [cs]<strong>Code (ASP)</strong>
09. [asp]<strong>Code (Android-Java)</strong>
10. <span class = "\\"notranslate\\"" ><font class = "css_code" ></font></span></font><pre class = "\\"brush:java\\"" ><font class = "css_code" ><font class = "css_code" ><strong>Code</strong>
11. <span class = "\\"notranslate\\"" ><pre><div class = "code" ><strong>Code (VBScript)</strong>
12. [vb]<strong>Code (VBScript)</strong>
13. [vb]<strong>Code (JavaScript)</strong>
14. <span class = "\\"notranslate\\"" ><font class = "css_code" ><pre class = "\\"brush:js\\"" >[url][img][email]<img src= "/images/resource/quote_ref.jpg" align= "absmiddle" > <a href= "#18" title= "ตอบความคิดเห็นที่ : 18 เขียนโดย : Chaidhanan เมื่อวันที่ 2014-11-22 10:06:34" >ตอบความคิดเห็นที่ : 18 เขียนโดย : Chaidhanan เมื่อวันที่ 2014-11-22 10:06:34</a>
15. <div style= "padding-left:30px;" ><div style= "padding-left:10px;padding-top:10px;padding-right:10px;padding-bottom:10px;BORDER-RIGHT: #b7deff 1px dotted; BORDER-TOP: #b7deff 1px dotted; BORDER-LEFT: #b7deff 1px dotted; BORDER-BOTTOM: #b7deff 1px dotted;" ><div align= "right" class = "sub_content" ><i>รายละเอียดของการตอบ ::</i><br></div>... ใส่ความคิดเห็นตรงนี้.......<img src= "/images/resource/quote_ref.jpg" align= "absmiddle" > <a href= "#19" title= "ตอบความคิดเห็นที่ : 19 เขียนโดย : cowboycnx เมื่อวันที่ 2014-11-22 10:31:42" >ตอบความคิดเห็นที่ : 19 เขียนโดย : cowboycnx เมื่อวันที่ 2014-11-22 10:31:42</a>
16. <div style= "padding-left:30px;" ><div style= "padding-left:10px;padding-top:10px;padding-right:10px;padding-bottom:10px;BORDER-RIGHT: #b7deff 1px dotted; BORDER-TOP: #b7deff 1px dotted; BORDER-LEFT: #b7deff 1px dotted; BORDER-BOTTOM: #b7deff 1px dotted;" ><div align= "right" class = "sub_content" ><i>รายละเอียดของการตอบ ::</i><br></div>... ใส่ความคิดเห็นตรงนี้.......<img src= "/images/resource/quote_ref.jpg" align= "absmiddle" > <a href= "#17" title= "ตอบความคิดเห็นที่ : 17 เขียนโดย : cowboycnx เมื่อวันที่ 2014-11-22 09:27:39" >ตอบความคิดเห็นที่ : 17 เขียนโดย : cowboycnx เมื่อวันที่ 2014-11-22 09:27:39</a>
17. <div style= "padding-left:30px;" ><div style= "padding-left:10px;padding-top:10px;padding-right:10px;padding-bottom:10px;BORDER-RIGHT: #b7deff 1px dotted; BORDER-TOP: #b7deff 1px dotted; BORDER-LEFT: #b7deff 1px dotted; BORDER-BOTTOM: #b7deff 1px dotted;" ><div align= "right" class = "sub_content" ><i>รายละเอียดของการตอบ ::</i><br></div>... ใส่ความคิดเห็นตรงนี้.......<img src= "/images/resource/quote_ref.jpg" align= "absmiddle" > <a href= "#15" title= "ตอบความคิดเห็นที่ : 15 เขียนโดย : Chaidhanan เมื่อวันที่ 2014-11-18 10:47:35" >ตอบความคิดเห็นที่ : 15 เขียนโดย : Chaidhanan เมื่อวันที่ 2014-11-18 10:47:35</a>
18. <div style= "padding-left:30px;" ><div style= "padding-left:10px;padding-top:10px;padding-right:10px;padding-bottom:10px;BORDER-RIGHT: #b7deff 1px dotted; BORDER-TOP: #b7deff 1px dotted; BORDER-LEFT: #b7deff 1px dotted; BORDER-BOTTOM: #b7deff 1px dotted;" ><div align= "right" class = "sub_content" ><i>รายละเอียดของการตอบ ::</i><br></div>... ใส่ความคิดเห็นตรงนี้.......<img src= "/images/resource/quote_ref.jpg" align= "absmiddle" > <a href= "#3" title= "ตอบความคิดเห็นที่ : 3 เขียนโดย : meannerss เมื่อวันที่ 2014-11-16 20:45:19" >ตอบความคิดเห็นที่ : 3 เขียนโดย : meannerss เมื่อวันที่ 2014-11-16 20:45:19</a>
19. <div style= "padding-left:30px;" ><div style= "padding-left:10px;padding-top:10px;padding-right:10px;padding-bottom:10px;BORDER-RIGHT: #b7deff 1px dotted; BORDER-TOP: #b7deff 1px dotted; BORDER-LEFT: #b7deff 1px dotted; BORDER-BOTTOM: #b7deff 1px dotted;" ><div align= "right" class = "sub_content" ><i>รายละเอียดของการตอบ ::</i><br></div>... ใส่ความคิดเห็นตรงนี้.......
20. </div></div>
21. </div></div>
22. </div></div>
23. </div></div>
24. </div></div>[/email][/img][/url]
25. </pre></font></span>
26. </div></pre></span></font>
27. </font></pre></pre></span></font></span></div><font class = "fontcode" >
28. </font></pre></font></span></font></span></div></pre></font></span><font class = "fontcode" ><font class = "fontcode" >
29. </font></font>
[/cs]
[/vb]
[/vb]
[/asp]
[/php]
|
 |
 |
 |
 |
Date :
2018-01-25 14:40:26 |
By :
tamada |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เค้าคงไม่ติดปัญหาแล้วมั้งครับ กระทู้ 2014
|
ประวัติการแก้ไข 2018-01-25 15:54:53
 |
 |
 |
 |
Date :
2018-01-25 15:54:39 |
By :
dudesaranyu |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|