|
 |
|
อยากทราบการใช้ while แบบนี้ถูกป่าวครับ มีฐานข้อมูล 2 ตาราง คือ1. ตารางภาพรวม 2. ตารางที่แสดงรายละเอียด |
|
 |
|
|
 |
 |
|
มีฐานข้อมูล 2 ตาราง คือ
1. ตารางภาพรวม
2. ตารางที่แสดงรายละเอียด
ผม while ข้อมูลจากตารางที่ 1 ออกมาทุกฟิว แล้วถ้าตารางที่ 2 มีความเกี่ยวกับตารางที่ 1 ก็จะแสดงออกมา ไม่ทราบว่าผมทำถูกรึป่าวครับ
head]Code (PHP)[/head]
<tr class="red">
<td height="30" colspan="8" align="center" valign="middle">ไม่พบข้อมูล</td>
</tr>
<?
}else{
while($rs_budget = mysql_fetch_array($obj_budget))
{
$date = $rs_budget["date_b"];
$inssst = $rs_budget["institution_id"];
$reg_alloc = $rs_budget["reg_bud"];
$reg_bring = $rs_budget["reg_bring"];
$invest_alloc = $rs_budget["invest_bud"];
$invest_bring = $rs_budget["invest_bring"];
$section = $rs_budget["section_name"];
$inst = $rs_budget["institution_name"];
if ($reg_alloc + $reg_bring ){
$reg_cl=number_format(($reg_bring*100)/$reg_alloc,2);
}else{
$reg_cl=number_format(0,2);
}
if ($invest_alloc + $invest_bring ){
$invest_cl=number_format(($invest_bring*100)/$invest_alloc,2);
}else{
$invest_cl=number_format(0,2);
}
//echo $reg_cl;
$sl_sub="SELECT
tb_sub_bring.id_sub,
tb_sub_bring.date_sub,
tb_sub_bring.sub_regbud,
tb_sub_bring.sub_regbring,
tb_sub_bring.sub_invbud,
tb_sub_bring.sub_invbring,
tb_sub.sub_id,
tb_sub.name_sub,
tb_sub.inst_id
FROM
tb_sub_bring
Inner Join tb_sub ON tb_sub_bring.id_sub = tb_sub.sub_id
WHERE MONTH(tb_sub_bring.date_sub)='$m' AND YEAR(tb_sub_bring.date_sub)='$y'
ORDER BY tb_sub_bring.id_sub ASC ";
$rs_sub = mysql_query($sl_sub);
$num_sub = mysql_num_rows($rs_sub);
$row_sub = mysql_fetch_array($rs_sub);
?>
<tr class="genn">
<td width="29%" align="left" valign="top"> <?print $section;?></td>
<td width="29%" align="left" valign="middle">
<? print $inst;
while($row_sub = mysql_fetch_array($rs_sub))
{
$iinst = $row_sub["inst_id"];
$sub_name = $row_sub["name_sub"];
$regbud = $row_sub["sub_regbud"];
$regbring = $row_sub["sub_regbring"];
$invbud = $row_sub["sub_invbud"];
$invbring = $row_sub["sub_invbring"];
echo $num_sub.'<BR>';
if ($inssst == $iinst){echo '<BR> '.$sub_name.' '.$regbud;}
}
//echo $inssst.' = '.$iinst;
?>
</td>
<td width="7%" align="right" valign="middle"
<?if ($reg_alloc != 0.000){
if ($reg_cl < $inv_q){?>
class="red"
<?}else{?>
class="green"
<?}}
else{?>
class="black"
<?}?>
><?print number_format($reg_alloc,3);
while($row_sub = mysql_fetch_array($rs_sub))
{
$iinst = $row_sub["inst_id"];
$sub_name = $row_sub["name_sub"];
$regbud = $row_sub["sub_regbud"];
$regbring = $row_sub["sub_regbring"];
$invbud = $row_sub["sub_invbud"];
$invbring = $row_sub["sub_invbring"];
if ($inssst == $iinst){echo '<BR> '.$regbud;}
}
?> </td>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-03-03 08:34:18 |
By :
oasiis |
View :
1430 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ข้อมูลที่แสดงออกมา ได้ผลลัพท์ตามที่ต้องการหรือเปล่าครับ ถ้าได้ ก็แสดงว่า ถูก ครับ
ปล. ผมยังไม่ได้ดูโค้ด แต่วิธีการเขียน มันมีหลายแบบครับ ขึ้นอยู่กับว่าเราจะเขียนอย่างไร
เหอๆ
|
 |
 |
 |
 |
Date :
2010-03-03 10:28:28 |
By :
kalamell |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|