<?php
$sql1='select group_id from table group by group_id';
$rs=$db->query( $sql1) or die ( ... );
while($ro=$rs->fetch_assoc()){
$sql2='select * from table where group_id = '.$ro['group_id'];
$rs2 = $db->query( $sql2) or die ( .... );
while( $ro2=$rs2->fetch_assoc()){
// show detail
}
}
?>
select แบบนี้ถูกไหม คับ หรือต้องเอา
$sql="SELECT * FROM tb_order o INNER JOIN tb_order_detail od ON od.ref_order_id=o.order_id GROUP BY order_id DESC";
บรรทัดนี้ไว้ด้วยคับ
Code (PHP)
$sql1='select order_id from tb_order group by order_id';
$rs=mysql_db_query($dbname,$sql1) or die (mysql_error());
while($ro=mysql_fetch_assoc($rs)){
$sql2='select * from tb_order_detail where ref_order_id = '.$ro['order_id'];
$rs2 = mysql_db_query($dbname,$sql2) or die (mysql_error());
while( $ro2=mysql_fetch_assoc($rs2)){
$order_qty=$ro2["order_qty"];
$sql1="SELECT SUM(order_qty) AS Sumqty FROM tb_order_detail od INNER JOIN tb_order o ON o.order_id=od.ref_order_id WHERE ref_order_id='$order_id'";
$result1=mysql_db_query($dbname,$sql1)or die(mysql_error());
while($rs=mysql_fetch_array($result1, MYSQL_ASSOC)){
$sumqty=$rs["Sumqty"];
}