<?php $no = 0; $sql = "SELECT * FROM booking WHERE month = '04' "; $result = mysql_query($sql);//คิวรี่ครั้งที่ 1 while( $rs = mysql_fetch_assoc($result) ){ $dpId = $rs["book_department_id"]; //คิวรี่ครั้งที่ 2 $qry = mysql_query("SELECT department_name FROM tb_department WHERE department_id = '".$dpId."' "); $rsDp = mysql_fetch_assoc($qry); $departMentName = $rsDp["department_name"]; echo "<br/>", $departMentName; } ?>
<?php //รายชื่อแผนกทั้งหมด $allDepart = array(); $qry = mysql_query("SELECT department_id, department_name FROM tb_department"); while($rsDp = mysql_fetch_assoc($qry)){ $allDepart[$rsDp['department_id ']] = $rsDp['department_name'] } $no = 0; $sql = "SELECT * FROM booking WHERE month = '04' "; $result = mysql_query($sql); while( $rs = mysql_fetch_assoc($result) ){ $dpId = $rs["book_department_id"]; $departMentName = $allDepart[$dpId]; echo "<br/>", $departMentName; } ?>