 |
PHP MYSQL ช่วยแนะนำ การ Query ให้แสดงผลใน 1 แถวหน่อยครับ |
|
 |
|
|
 |
 |
|
แก้ statement นิดหน่อย
Code
SELECT n.id,
n.nu_code,
n.intensity,
u.unit,
nd.so_name,
nd.intensity i1,
ut.unit u1
FROM nut n join nut_detail nd on n.id = nd.id
join unit_t u on n.unit_id = u.unit_id
join unit_t ut on nd.unit_id = ut.unit_id
เอา result ที่ได้มาสร้างเป็น array ใหม่ ตรวจสอบว่ามีแล้ว หรือไม่
ถ้ามี เอารายการใหม่ที่ได้ ไป ต่อท้าย รายการเก่า
Code (PHP)
$new_ar = array();
while($ro=$rs->fetch_assoc()){
if(!isset($new_arr[$ro['nu_code'])) $new_ar[$ro['nu_code']]=array();
$new_ar[$ro['nu_code']][0]=$ro;
}
foreach($new_ar as $ro_list){
foreach( $ro_list as $idx=>$ro){
if ($idx==0){
echo $ro['id'], $ro['nu_code'], $ro['unit'];
}
echo $ro['so_name'], $ro['i1'], $ro['u1'];
}
}
|
 |
 |
 |
 |
Date :
2016-02-13 18:14:02 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|