|
![](/images/resource/spacer.gif) |
|
สอบถามการ query ข้อมูลเพื่อ ออกรายงานแยกตามประเภท ขอบคุณครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
$result = QueryFuntion('SELECT ProductType , ProductName from product group by ProductType '); // เอาไปคิวรี่ให้ได้ ค่าออกมาเป็น array
$result2 = QueryFuntion('SELECT * from product '); //เอาไปคิวรี่ให้ได้ ค่าออกมาเป็น array ตอน while ค่าเป็น result เป็น กลุ่ม
Code (PHP)
while($row=mysql_fetch_object){
$result[$row['ProductType']] = $row
}
foreach($result => $head){
echo $head['ProductName'];
foreach($result2[$head['ProductName ']] => $sub){
echo $sub['ProductID'];
}
}
code ตัวอย่างนะคับ เอาไปลองปรับดู ผมอาจจะเขียนบางตัวผิด >< ปกติ เวลา คิวรี่ข้อมูลทำเป็นฟังชั่นไว้เลย ไม่ค่อยได้จำเท่าไร
|
ประวัติการแก้ไข 2015-11-12 20:53:09 2015-11-12 20:54:06
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-11-12 20:52:52 |
By :
progamer2000 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
จากคำสั่งนี้
$result = $db->query('SELECT ProductType , ProductName, fld_อื่นๆ from product order by ProductType, ProductName ');
ให้สร้างตัวแปรมาเก็บค่าของ ProductType
เวลานำมา while ให้ตรวจสอบ ชื่อเหมือนกัน ถ้าเหมือนให้ใส่ค่าว่าง ถ้าไม่เหมือน ให้พิมพ์ค่าใหม่
Code (PHP)
$ProductType='';
$result = $db->query('SELECT ProductType , ProductName, fld_อื่นๆ from product order by ProductType, ProductName ');
while( $row=$result->fetch_assoc()){
echo ($ProductType==$row['ProductType']? '' : $row['ProductType'];
$ProductType=$row['ProductType']; //กำหนดค่าเพื่อไว้ตรวจสอบต่อไป
echo 'field อื่นๆ';
}
|
ประวัติการแก้ไข 2015-11-13 07:42:42 2015-11-13 07:43:29
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-11-13 07:41:18 |
By :
NewbiePHP |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 05
|