การออกรายงาน php to PDF แบบมีหลายSQL และหลายเงื่อนไข
ตอนนี้กำลังทำโปรเจคอยู่ค่ะ แล้วต้องการออกรายงานเป็น PDF แต่ว่ามีหลาย SQL และหลายเงื่อนไขมาก เลยไม่รู้จะทำอย่างไรค่ะ ลองทำตามในเว็บที่แนะนำดูส่วนใหญ่จะเป็นSQL เดียว หรือเงื่อนไขที่ไม่ซับซ้อน รบกวนฝากดูให้หน่อยนะคะ
Code
<body>
<div id="main">
<!-- start content -->
<div id="content">
<div align="left">
<p><span class="style6"> <img src="images/table.png" width="24" height="24" align="absmiddle" /> ข้อมูลบัญชีย่อยเงินฝาก(บช.๑๑)</span></p>
<p> </p>
<form id="form2" name="form2" method="post" action="search_accdep.php?acc_unit_id=<? echo $acc_unit_id; ?>&acct_id=<? echo $acct_id;?>&unit_redep_id=<? echo $unit_redep_id;?>&unit_dep_id=<? echo $unit_dep_id;?>&year=<? echo $year;?>">
<table width="1096" border="0" cellpadding="1" cellspacing="1">
<tr>
<td height="25" colspan="12" class="style15"><img src="images/page_add.png" alt="" width="16" height="16" /> <strong><a href="form_accdeposit.php">เพิ่มข้อมูลบัญชีย่อย</a> <img src="images/page_add.png" alt="" width="16" height="16" /><a href="form_accdeposit_bail.php">เพิ่มข้อมูลบัญชีย่อยเงินประกัน</a></strong></td>
</tr>
<tr>
<td height="19" colspan="12" class="style15"> </td>
</tr>
<tr>
<td height="25" colspan="12" class="style15"><strong><img src="images/search.png" width="16" height="16" /> ค้นหาข้อมูลบัญชีย่อยเงินฝาก<span class="style11">(**กรุณาเลือกให้ข้อมูลให้ครบถ้วน)</span></strong></td>
</tr>
<tr>
<td width="151" class="style15"> ส่วนราชการ </td>
<td width="13" class="style15"><div align="center">::</div></td>
<td width="177" class="style15"><label> <font id="gover">
<select name="acc_unit_id" id="acc_unit_id">
</select>
</font> </label></td>
<td width="76" class="style13">ระหว่างวันที่</td>
<td width="21" class="style13"><div align="center" class="style14">::</div></td>
<td width="134" class="style13"><input name="cdate1" type="text" id="cdate1" size="15" maxlength="10" value="<? echo $cdate1; ?>" /></td>
<td width="65" class="style13">ถึงวันที่</td>
<td width="18" class="style13"><div align="center" class="style14">::</div></td>
<td width="132" class="style13"><input name="cdate2" type="text" id="cdate2" size="15" maxlength="10" value="<? echo $cdate2; ?>" /></td>
<td width="95" class="style13"> </td>
<td width="20" class="style13"> </td>
<td width="157" class="style13"> </td>
</tr>
<tr>
<td class="style15"> ประเภทบัญชีย่อย </td>
<td class="style15"><div align="center">::</div></td>
<td class="style15"><label><font id="dep_acc">
<select name="acct_id" id="acct_id">
</select>
</font></font></font></font></label></td>
<td class="style15">ผู้รับฝาก</td>
<td class="style15"><div align="center">::</div></td>
<td class="style15"><font id="gover_dep">
<select name="acc_unit_redep_id" id="acc_unit_redep_id">
</select>
</font></td>
<td class="style15">ผู้ฝาก</td>
<td class="style15"><div align="center">::</div></td>
<td class="style15"><font id="gover_depos">
<select name="acc_unit_dep_id" id="acc_unit_dep_id">
</select>
</font></td>
<td class="style15">บุคคลภายนอก</td>
<td class="style15"><div align="center">::</div></td>
<td class="style15"><span class="style13">
<input name="own" type="text" id="own" size="20" maxlength="50" />
</span></td>
</tr>
<tr>
<td colspan="12"><div align="center">
<input type="submit" name="button2" id="button2" value="แสดง" />
<input type="reset" name="button3" id="button3" value="ยกเลิก" />
</div>
<div align="center"></div>
</label></td>
</tr>
</table>
</form>
<hr />
<div align="center">
<!-- กำหนดเงื่อนไข โดยตรวจสอบว่าผู้รับฝากกับผู้ฝากเป็นค่าว่างใช่หรือไม-->
<?
$yy1=substr($_POST['cdate1'],6,4);
$mm1=substr($_POST['cdate1'],3,2);
$dd1=substr($_POST['cdate1'],0,2);
$ddd1=$yy1."-".$mm1."-".$dd1." "."00".":"."00".":"."00";
$yy2=substr($_POST['cdate2'],6,4);
$mm2=substr($_POST['cdate2'],3,2);
$dd2=substr($_POST['cdate2'],0,2);
$ddd2=$yy2."-".$mm2."-".$dd2." "."23".":"."59".":"."59";
if ($acc_unit_redep_id=='0'&&$acc_unit_dep_id=='0'){ //echo test;
//echo "unit_id=".$acc_unit_id;
//echo "acct_id=".$acct_id;
//ดึงข้อมูลชื่อส่วนราชการออกมาแสดง
$sql4 = "select * from acc_deposit,acc_unit where acc_unit.acc_unit_id=acc_deposit.acc_unit_id and acc_deposit.acc_unit_id ='$acc_unit_id'";
//echo $sql4;
$data4=mysql_query($sql4);
$result4=mysql_fetch_array($data4);
$unit_name = $result4["acc_unit_name"];
//echo "<br />unit_name =".$unit_name;
//ดึง ประเภทบัญชีย่อย และข้อมูลอื่นๆ ออกมาแสดง
$sql2 = "select * from acc_deposit,acc_unit,acc_type,acc_unit_redep where ";
$sql2.= "acc_deposit.acc_unit_id = acc_unit.acc_unit_id and acc_deposit.acct_id = acc_type.acct_id and ";
$sql2.= "acc_deposit.acc_unit_redep_id = acc_unit_redep.acc_unit_id and ";
//$sql2.= "acc_deposit.acc_unit_dep_id = acc_unit_dep.acc_unit_id and ";
$sql2.= "acc_depos_date between '$ddd1' and '$ddd2' and acc_deposit.acc_unit_id='$acc_unit_id' and acc_deposit.act_id='01' and acc_deposit.acct_id='$acct_id' ";
//echo $sql2;
$data5=mysql_query($sql2);
$result5=mysql_fetch_array($data5);
$unit_name5 = $result5["acc_unit_name"];
$acct_name5 = $result5["acct_name"];
$m = substr($result5["acc_depos_date"],5,2);
$d = substr($result5["acc_depos_date"],8,2);
$y = substr($result5["acc_depos_date"],0,4);
$Num_Rows = mysql_num_rows($data5); // นับจำนวนแถว
/*$Per_Page = 20; // จำนวน record ต่อ 1 หน้
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$sql2.=" LIMIT $Page_Start , $Per_Page;"; // code ต่อจาก sql ในการกำหนด record*/
$data5= mysql_query($sql2);
if ($Num_Rows==" ") { //ตรวจสอบจำนวนแถวหลังจาก query ข้อมูลว่าเท่ากับค่าว่างหรือไม่ ?>
<br/>
<span class="style8">** ไม่พบข้อมูล ** </span><br />
</p>
<?
} else { ?>
</div>
<p align="center"><span class="style8">ส่วนราชการ <? echo $unit_name; ?></span></p>
<p align="center"><span class="style8">บัญชีย่อย <? echo $acct_name5; ?></span></p>
<p align="center"> </p>
<table width="980" height="170" border="0" align="center" class="scrolltable columnar">
<thead><tr>
<td width="82" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">วัน/เดือน/ปี</div>
</div></td>
<td height="31" colspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ที่เอกสาร</div>
</div></td>
<td width="65" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ผู้รับฝาก</div>
</div></td>
<td width="66" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ผู้ฝาก</div>
</div></td>
<td width="222" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">รายการ</div>
</div></td>
<td width="66" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">หน้าบัญชี</div>
</div></td>
<td width="105" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ฝาก</div>
</div></td>
<td width="115" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ถอน</div>
</div></td>
<td width="116" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">คงเหลือ</div>
</div></td>
</tr>
<tr>
<td width="55" height="25" bgcolor="#0071BC" class="style3"><div align="center" class="style4">ผู้รับ</div></td>
<td width="46" bgcolor="#0071BC" class="style3"><div align="center" class="style4">ผู้ยืม</div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
</tr></thead>
<?php
/* $i = 1;
if($Page > 1)
{
$i = ($Per_Page * ($Page-1)) + 1;
}*/
while($result7=mysql_fetch_array($data5)){
$d1 = substr($result7["acc_depos_date"],8,2);
$m1 = substr($result7["acc_depos_date"],5,2);
$y1 = substr($result7["acc_depos_date"],0,4);
$acc_depos_date = $d1."/".$m1."/".$y1;
?>
<tbody><tr bgcolor="#CCEEFF">
<td height="25"><div align="center" class="style16"><? echo $acc_depos_date;?></div></td>
<td height="25"><div align="center" class="style16">
<div align="left"> <? echo $result7["acc_depos_rec"]?></div>
</div></td>
<td height="25"><div align="center" class="style16">
<div align="left"> <? echo $result7["acc_depos_bor"]?></div>
</div></td>
<td><div align="center" class="style16"><?
$sql3 = "select * from acc_deposit,acc_unit,acc_type,acc_unit_redep where ";
$sql3.= "acc_deposit.acc_unit_id = acc_unit.acc_unit_id and acc_deposit.acct_id = acc_type.acct_id and ";
$sql3.= "acc_deposit.acc_unit_redep_id = acc_unit_redep.acc_unit_id and ";
$sql3.= "acc_depos_date between '$ddd1' and '$ddd2' and acc_deposit.acc_unit_id='$acc_unit_id' and acc_deposit.act_id='01' and acc_deposit.acc_depos_id='$result7[0]' and acc_deposit.acct_id='$acct_id' ";
$data6=mysql_query($sql3);
$result8=mysql_fetch_array($data6);
echo $result8["acc_unit_name"]?> </div></td>
<td><div align="center" class="style16"><?
if($result7["acc_unit_dep_id"]==0){ echo $result7["acc_depos_own"]; } else {
$sql5 = "select * from acc_deposit,acc_unit,acc_type,acc_unit_dep where ";
$sql5.= "acc_deposit.acc_unit_id = acc_unit.acc_unit_id and acc_deposit.acct_id = acc_type.acct_id and ";
$sql5.= "acc_deposit.acc_unit_dep_id = acc_unit_dep.acc_unit_id and ";
$sql5.= "acc_depos_date between '$ddd1' and '$ddd2' and acc_deposit.acc_unit_id='$acc_unit_id' and acc_deposit.act_id='01' and acc_deposit.acc_depos_id='$result7[0]' and acc_deposit.acct_id='$acct_id' ";
$data7=mysql_query($sql5);
$result9=mysql_fetch_array($data7);
echo $result9["acc_unit_name"]; }?></div></td>
<td><div align="left" class="style16"> <? echo $result7["acc_depos_de"]?> <? if($acct_id=='09') { if( $result7["ins_id"]=='1'){echo "(ประเภทเงินมัดจำ)";} else if( $result7["ins_id"]=='2'){echo "(ประเภทประกันสัญญา)";} } ?></div></td>
<td><div align="center" class="style16"><? echo $result7["acc_depos_page"]?></div></td>
<td><div align="right" class="style16"><? $am1=$result7["acc_depos_amount"]; echo number_format($am1,2); $total_am1+=$am1; ?> </div></td>
<td><div align="center" class="style16"><div align="right"><? echo number_format(0,2); ?> </div>
</div></td>
<td><div align="center" class="style16"><div align="right"><? if($acct_id=='09') {?><a href="display_accdep_draw_bail.php?temp=<? echo $result7["acc_depos_id"]; ?>&temp1=<? echo $result7["acct_id"]; ?>&temp2=<? echo $result4["acc_unit_id"]; ?>&temp3=<? echo $result7["acc_unit_redep_id"]; ?>&temp4=<? echo $result7["acc_unit_dep_id"]; ?>&temp5=<? echo $year; ?>"><? echo number_format($am1,2); ?></a><? } else {?><a href="display_accdep_draw.php?temp=<? echo $result7["acc_depos_id"]; ?>&temp1=<? echo $result7["acct_id"]; ?>&temp2=<? echo $result4["acc_unit_id"]; ?>&temp3=<? echo $result7["acc_unit_redep_id"]; ?>&temp4=<? echo $result7["acc_unit_dep_id"]; ?>&temp5=<? echo $year; ?>"><? echo number_format($am1,2); ?></a><? } ?> </div>
</div></td>
</tr>
<?
$sql7 = "select * from acc_deposit_draw where acc_depos_id ='$result7[0]' and act_id='01' order by acc_depdraw_date asc";
$data11 = mysql_query($sql7);
$Num_Rows7 = mysql_num_rows($data11); //
$r_amount =0;
while($result11=mysql_fetch_array($data11)){
?>
<tr bgcolor="#ECF9FF">
<td height="25"> </td>
<td height="25"> </td>
<td height="25"> </td>
<td> </td>
<td> </td>
<td><div align="left" class="style16"> - <? echo เลขที่เอกสารถอนเงิน."::".$result11["acc_depdraw_doc"]?> </div></td>
<td> </td>
<td> </td>
<td><div align="right" class="style16"><? echo number_format($result11["acc_depdraw_amount"],2); $total_am+=$result11['acc_depdraw_amount'];?> </div></td>
<td><div align="right" class="style16">
<?
//$acc_am=$result["acc_rec_amount"];
$sql8 = "select * from acc_deposit,acc_deposit_draw where acc_deposit.acc_depos_id=acc_deposit_draw.acc_depos_id and acc_deposit_draw.acc_depos_id='$result11[4]' and acc_deposit_draw.acc_depdraw_id = '$result11[0]' ";
//echo $sql8;
$data12 = mysql_query($sql8);
while($result12=mysql_fetch_array($data12)){
$depos_amount = $result12['acc_depos_amount'];
//echo $depos_amount;
$depdraw_amount = $result12['acc_depdraw_amount'];
//echo $depdraw_amount ;
$r_amount-=$depdraw_amount;
//echo r_amount."=".$r_amount;
//$acc_am-=$ref_amount ;
//echo r_amount1."=".$r_amount1 -= $ref_amount;
$sql9 = "select * from acc_deposit,acc_deposit_draw where acc_deposit.acc_depos_id=acc_deposit_draw.acc_depos_id and acc_deposit_draw.acc_depos_id='$result12[0]' and acc_deposit_draw.acc_depdraw_id = '$result12[18]' ";
//echo $sql9;
$data13 = mysql_query($sql9);
// echo $sql3;
//$result4=mysql_fetch_array($data3);
// $depo_amount = $result3['depo_amount'];
while($result13=mysql_fetch_array($data13)){
$depos_amount = $result13['acc_depos_amount'];
$depdraw_amount = $result13['acc_depdraw_amount'];
//echo r_amount."=".$r_amount;
//echo ref_amount."=".$ref_amount;
//echo $r_amount;
$am=$r_amount+$depos_amount;
//echo $am;
echo number_format($am,2);
}
}
?> </div></td>
</tr>
<?php } }
$i++; }
?>
<tr bgcolor="#CCEEFF">
<td height="25" colspan="7"><div align="center"><strong>รวม</strong></div></td>
<td><div align="right" class="style16"><? echo number_format($total_am1,2);?> </div></td>
<td><div align="right" class="style16"><? echo number_format($total_am,2);?> </div></td>
<td><div align="right" class="style16"><? $sum_total= $total_am1-$total_am; echo number_format($sum_total,2);?> </div></td>
</tr></tbody>
</table>
<div align="center">
<?
} ?>
<!-- กำหนดเงื่อนไข โดยตรวจสอบว่าผู้รับฝากกับผู้ฝากไม่เป็นค่าว่าง-->
<? if ($acc_unit_redep_id!='0'&&$acc_unit_dep_id!='0') {
//echo test;
//ดึงข้อมูลชื่อส่วนราชการออกมาแสดง
$sql4 = "select * from acc_deposit,acc_unit where acc_unit.acc_unit_id=acc_deposit.acc_unit_id and acc_deposit.acc_unit_id ='$acc_unit_id'";
//echo $sql4;
$data4=mysql_query($sql4);
$result4=mysql_fetch_array($data4);
$unit_name = $result4["acc_unit_name"];
//เงื่อนไขที่ 3 แสดงชื่อผู้รับ
$sql = "select * from acc_deposit,acc_unit_dep where ";
$sql.= "acc_deposit.acc_unit_dep_id = acc_unit_dep.acc_unit_id ";
$sql.= "and acc_deposit.acc_unit_dep_id='$acc_unit_dep_id' and acc_deposit.act_id='01' ";
$data=mysql_query($sql);
$result3=mysql_fetch_array($data);
$unit_name_dep = $result3["acc_unit_name"];
//echo "<br />unit_name_dep=".$unit_name_dep;
//เงื่อนไขที่ 2 แสดงชื่อผู้ยืม
$sql = "select * from acc_deposit,acc_unit_redep where ";
$sql.= "acc_deposit.acc_unit_redep_id = acc_unit_redep.acc_unit_id ";
$sql.= "and acc_deposit.acc_unit_redep_id='$acc_unit_redep_id' and acc_deposit.act_id='01' ";
$data=mysql_query($sql);
$result2=mysql_fetch_array($data);
$unit_name_redep = $result2["acc_unit_name"];
//เงื่อนไขที่ 1 แสดงส่วนราชการ และบัญชีย่อย
$sql = "select * from acc_deposit,acc_unit,acc_type,acc_unit_redep,acc_unit_dep where ";
$sql.= "acc_deposit.acc_unit_id = acc_unit.acc_unit_id and acc_deposit.acct_id = acc_type.acct_id and ";
$sql.= "acc_deposit.acc_unit_redep_id = acc_unit_redep.acc_unit_id and ";
$sql.= "acc_deposit.acc_unit_dep_id = acc_unit_dep.acc_unit_id and ";
$sql.= "acc_depos_date between '$ddd1' and '$ddd2' and acc_deposit.acc_unit_id='$acc_unit_id' and acc_deposit.acc_unit_redep_id='$acc_unit_redep_id' and acc_deposit.acc_unit_dep_id='$acc_unit_dep_id' and acc_deposit.acct_id='$acct_id' and acc_deposit.act_id='01' ";
$data=mysql_query($sql);
$result1=mysql_fetch_array($data);
//$unit_name = $result1["acc_unit_name"];
$acct_name = $result1["acct_name"];
$m = substr($result1["acc_depos_date"],5,2);
$d = substr($result1["acc_depos_date"],8,2);
$y = substr($result1["acc_depos_date"],0,4);
$Num_Rows = mysql_num_rows($data); // นับจำนวนแถว
/*$Per_Page = 20; // จำนวน record ต่อ 1 หน้
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$sql.=" LIMIT $Page_Start , $Per_Page;"; // code ต่อจาก sql ในการกำหนด record*/
$data= mysql_query($sql);
if ($Num_Rows==" ") { ?>
<br/>
<span class="style8">** ไม่พบข้อมูล ** </span><br />
</p>
<?
} else {
?>
</div>
<p align="center"><span class="style8">ส่วนราชการ <? echo $unit_name; ?></span></p>
<p align="center"><span class="style8">บัญชีย่อย <? echo $acct_name; ?></span></p>
<table width="712" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="498"><span class="style9">ผู้รับฝาก ::<span class="style8"> <? echo $unit_name_redep; ?></span></span></td>
<td width="40"><span class="style9">ผู้ฝาก</span></td>
<td width="10"><div align="center"><span class="style9">::</span></div></td>
<td width="151"><span class="style8"><? echo $unit_name_dep; ?></span></td>
</tr>
</table>
<p align="center"><br />
</p>
</div>
<table width="866" height="165" border="0" align="center" class="scrolltable columnar">
<thead> <tr>
<td width="80" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">วัน/เดือน/ปี</div>
</div></td>
<td height="29" colspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ที่เอกสาร</div>
</div></td>
<td width="213" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">รายการ</div>
</div></td>
<td width="62" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">หน้าบัญชี</div>
</div></td>
<td width="111" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ฝาก</div>
</div></td>
<td width="118" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ถอน</div>
</div></td>
<td width="115" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">คงเหลือ</div>
</div></td>
</tr>
<tr>
<td width="72" height="28" bgcolor="#0071BC" class="style3"><div align="center" class="style4">ผู้รับ</div></td>
<td width="61" bgcolor="#0071BC" class="style3"><div align="center" class="style4">ผู้ฝาก</div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
</tr></thead>
<?php
/* $i = 1;
if($Page > 1)
{
$i = ($Per_Page * ($Page-1)) + 1;
}*/
while($result=mysql_fetch_array($data)){
$d1 = substr($result["acc_depos_date"],8,2);
$m1 = substr($result["acc_depos_date"],5,2);
$y1 = substr($result["acc_depos_date"],0,4);
//list($h1,$h2,$h3)=explode("-",$result[6]);
$acc_depos_date = $d1."/".$m1."/".$y1;
$st = substr($result["amount"],-2);
$st1 = substr($result["accde_total"],-2);
?>
<tbody> <tr bgcolor="#CCEEFF">
<td height="28"><div align="center" class="style16"><? echo $acc_depos_date;?></div></td>
<td height="28"><div align="center" class="style16">
<div align="left"> <? echo $result["acc_depos_rec"]?></div>
</div></td>
<td height="28"><div align="center" class="style16">
<div align="left"> <? echo $result["acc_depos_bor"]?></div>
</div></td>
<td><div align="left" class="style16"> <? echo $result["acc_depos_de"]?></div></td>
<td><div align="center" class="style16"><? echo $result["acc_depos_page"]?></div></td>
<td><div align="right" class="style16">
<? //if ($result["trans_id"]=='05') {
$am1=$result["acc_depos_amount"]; echo number_format($am1,2); $total_am1+=$am1;
//} else { echo number_format(0,2); } ?> </div></td>
<td><div align="center" class="style16">
<div align="right">
<? if ($result["trans_id"]=='06') { $am2=$result["acc_depos_amount"]; echo number_format($am2,2); } else { echo number_format(0,2); } ?> </div>
</div></td>
<td><div align="right" class="style16">
<? if($acct_id=='09') { ?><a href="display_accdep_draw_bail.php?temp=<? echo $result["acc_depos_id"]; ?>&temp1=<? echo $result["acct_id"]; ?>&temp2=<? echo $result4["acc_unit_id"]; ?>&temp3=<? echo $result2["acc_unit_redep_id"]; ?>&temp4=<? echo $result3["acc_unit_dep_id"]; ?>&temp5=<? echo $year; ?>"><? echo number_format($am1,2); ?></a><? } else {?> <a href="display_accdep_draw.php?temp=<? echo $result["acc_depos_id"]; ?>&temp1=<? echo $result["acct_id"]; ?>&temp2=<? echo $result4["acc_unit_id"]; ?>&temp3=<? echo $result2["acc_unit_redep_id"]; ?>&temp4=<? echo $result3["acc_unit_dep_id"]; ?>&temp5=<? echo $year; ?>"><? echo number_format($am1,2); ?><? } ?> </a></div></td>
</tr>
<? $sql4 = "select * from acc_deposit_draw where acc_depos_id ='$result[0]' and act_id='01' order by acc_depdraw_date asc";
$data8 = mysql_query($sql4);
$Num_Rows4 = mysql_num_rows($data8); //
$r_amount =0;
while($result8=mysql_fetch_array($data8)){
?>
<tr bgcolor="#ECF9FF">
<td height="25"> </td>
<td height="25"> </td>
<td height="25"> </td>
<td><div align="left" class="style16"> - <? echo เลขที่เอกสารถอนเงิน."::".$result8["acc_depdraw_doc"]?> </div></td>
<td> </td>
<td> </td>
<td><div align="right" class="style16"><? echo number_format($result8["acc_depdraw_amount"],2); $total_am+=$result8['acc_depdraw_amount'];?> </div></td>
<td><div align="right" class="style16"><?
//$acc_am=$result["acc_rec_amount"];
$sql5 = "select * from acc_deposit,acc_deposit_draw where acc_deposit.acc_depos_id=acc_deposit_draw.acc_depos_id and acc_deposit_draw.acc_depos_id='$result8[4]' and acc_deposit_draw.acc_depdraw_id = '$result8[0]' ";
$data9 = mysql_query($sql5);
while($result9=mysql_fetch_array($data9)){
$depos_amount = $result9['acc_depos_amount'];
$depdraw_amount = $result9['acc_depdraw_amount'];
$r_amount-=$depdraw_amount;
//echo r_amount."=".$r_amount;
//$acc_am-=$ref_amount ;
//echo r_amount1."=".$r_amount1 -= $ref_amount;
$sql6 = "select * from acc_deposit,acc_deposit_draw where acc_deposit.acc_depos_id=acc_deposit_draw.acc_depos_id and acc_deposit_draw.acc_depos_id='$result9[0]' and acc_deposit_draw.acc_depdraw_id = '$result9[18]' ";
$data10 = mysql_query($sql6);
// echo $sql3;
//$result4=mysql_fetch_array($data3);
// $depo_amount = $result3['depo_amount'];
while($result10=mysql_fetch_array($data10)){
$depos_amount = $result10['acc_depos_amount'];
$depdraw_amount = $result10['acc_depdraw_amount'];
//echo r_amount."=".$r_amount;
//echo ref_amount."=".$ref_amount;
$am=$r_amount+$depos_amount;
echo number_format($am,2);
}
}
?> </div></td>
</tr>
<?php }
}
$i++; }
?>
<tr bgcolor="#CCEEFF">
<td height="25" colspan="5"><div align="center"><strong>รวม</strong></div></td>
<td><div align="right" class="style16"><? echo number_format($total_am1,2);?> </div></td>
<td><div align="right" class="style16"><? echo number_format($total_am,2);?> </div></td>
<td><div align="right" class="style16"><? $sum_total= $total_am1-$total_am; echo number_format($sum_total,2);?> </div></td>
</tr></tbody>
</table>
<p><? } ?>
</p>
<p><br />
</p>
<div align="center">
<!-- กำหนดเงื่อนไข โดยตรวจสอบว่าผู้รับฝากไม่เป็นค่าว่างและผู้ฝากเป็นค่าว่าง-->
<? if ($acc_unit_redep_id!='0'&&$acc_unit_dep_id=='0') {
//echo test;
//ดึงข้อมูลชื่อส่วนราชการออกมาแสดง
$sql4 = "select * from acc_deposit,acc_unit where acc_unit.acc_unit_id=acc_deposit.acc_unit_id and acc_deposit.acc_unit_id ='$acc_unit_id'";
//echo $sql4;
$data4=mysql_query($sql4);
$result4=mysql_fetch_array($data4);
$unit_name = $result4["acc_unit_name"];
//เงื่อนไขที่ 3 แสดงชื่อผู้ฝาก
$sql = "select * from acc_deposit where ";
$sql.= "acc_depos_own = '$own' and acc_deposit.act_id='01' ";
$data=mysql_query($sql);
$result3=mysql_fetch_array($data);
$depos_own = $result3["acc_depos_own"];
//echo "<br />unit_name_dep=".$unit_name_dep;
//เงื่อนไขที่ 2 แสดงชื่อผู้รับฝาก
$sql = "select * from acc_deposit,acc_unit_redep where ";
$sql.= "acc_deposit.acc_unit_redep_id = acc_unit_redep.acc_unit_id ";
$sql.= "and acc_deposit.acc_unit_redep_id='$acc_unit_redep_id' and acc_deposit.act_id='01' ";
$data=mysql_query($sql);
$result2=mysql_fetch_array($data);
$unit_name_redep = $result2["acc_unit_name"];
//เงื่อนไขที่ 1 แสดงส่วนราชการ และบัญชีย่อย
$sql = "select * from acc_deposit,acc_unit,acc_type,acc_unit_redep where ";
$sql.= "acc_deposit.acc_unit_id = acc_unit.acc_unit_id and acc_deposit.acct_id = acc_type.acct_id and ";
$sql.= "acc_deposit.acc_unit_redep_id = acc_unit_redep.acc_unit_id and ";
//$sql.= "acc_deposit.acc_unit_dep_id = acc_unit_dep.acc_unit_id and ";
$sql.= "acc_depos_date between '$ddd1' and '$ddd2' and acc_deposit.acc_unit_id='$acc_unit_id' and acc_deposit.acc_unit_redep_id='$acc_unit_redep_id' and acc_depos_own = '$own' and acc_deposit.acct_id='$acct_id' and acc_deposit.act_id='01' ";
$data=mysql_query($sql);
$result1=mysql_fetch_array($data);
//$unit_name = $result1["acc_unit_name"];
$acct_name = $result1["acct_name"];
$m = substr($result1["acc_depos_date"],5,2);
$d = substr($result1["acc_depos_date"],8,2);
$y = substr($result1["acc_depos_date"],0,4);
$Num_Rows = mysql_num_rows($data); // นับจำนวนแถว
$Per_Page = 20; // จำนวน record ต่อ 1 หน้
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$sql.=" LIMIT $Page_Start , $Per_Page;"; // code ต่อจาก sql ในการกำหนด record
$data= mysql_query($sql);
if ($Num_Rows==" ") { ?>
<br/>
<span class="style8">** ไม่พบข้อมูล ** </span><br />
</p>
<?
} else {
?>
<p align="center"><span class="style8">ส่วนราชการ <? echo $unit_name; ?></span></p>
<p align="center"><span class="style8">บัญชีย่อย <? echo $acct_name; ?></span></p>
<table width="746" height="26" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="498"><div align="left"><span class="style9">ผู้รับฝาก ::<span class="style8"> <? echo $unit_name_redep; ?></span></span></div></td>
<td width="40"><div align="left"><span class="style9">ผู้ฝาก</span></div></td>
<td width="10"><div align="left"><span class="style9">::</span></div></td>
<td width="151"><div align="left"><span class="style8"><? echo $depos_own; ?></span></div></td>
</tr>
</table>
</div>
<p align="center"><br />
</p>
<table width="866" height="159" border="0" align="center" class="scrolltable columnar">
<thead><tr>
<td width="80" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">วัน/เดือน/ปี</div>
</div></td>
<td height="31" colspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ที่เอกสาร</div>
</div></td>
<td width="213" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">รายการ</div>
</div></td>
<td width="62" rowspan="2" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">หน้าบัญชี</div>
</div></td>
<td width="111" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ฝาก</div>
</div></td>
<td width="118" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">ถอน</div>
</div></td>
<td width="115" bgcolor="#0071BC" class="style3"><div align="center" class="style4">
<div align="center">คงเหลือ</div>
</div></td>
</tr>
<tr>
<td width="72" height="25" bgcolor="#0071BC" class="style3"><div align="center" class="style4">ผู้รับ</div></td>
<td width="61" bgcolor="#0071BC" class="style3"><div align="center" class="style4">ผู้ฝาก</div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
<td bgcolor="#0071BC"><div align="center" class="style4">บาท/ส.ต.</div>
<div align="center" class="style4"></div></td>
</tr></thead>
<?php
/* $i = 1;
if($Page > 1)
{
$i = ($Per_Page * ($Page-1)) + 1;
}*/
while($result=mysql_fetch_array($data)){
$d1 = substr($result["acc_depos_date"],8,2);
$m1 = substr($result["acc_depos_date"],5,2);
$y1 = substr($result["acc_depos_date"],0,4);
//list($h1,$h2,$h3)=explode("-",$result[6]);
$acc_depos_date = $d1."/".$m1."/".$y1;
$st = substr($result["amount"],-2);
$st1 = substr($result["accde_total"],-2);
?>
<tbody><tr bgcolor="#CCEEFF">
<td height="28"><div align="center" class="style16"><? echo $acc_depos_date;?></div></td>
<td height="28"><div align="center" class="style16">
<div align="left"> <? echo $result["acc_depos_rec"]?></div>
</div></td>
<td height="28"><div align="center" class="style16">
<div align="left"> <? echo $result["acc_depos_bor"]?></div>
</div></td>
<td><div align="left" class="style16"> <? echo $result["acc_depos_de"]?></div></td>
<td><div align="center" class="style16"><? echo $result["acc_depos_page"]?></div></td>
<td><div align="right" class="style16">
<? //if ($result["trans_id"]=='05') {
$am1=$result["acc_depos_amount"]; echo number_format($am1,2); $total_am1+=$am1;
//} else { echo number_format(0,2); } ?> </div> </td>
<td><div align="center" class="style16">
<div align="right">
<? if ($result["trans_id"]=='06') { $am2=$result["acc_depos_amount"]; echo number_format($am2,2); } else { echo number_format(0,2); } ?> </div>
</div></td>
<td><div align="right" class="style16">
<? if($acct_id=='09') { ?><a href="display_accdep_draw_bail.php?temp=<? echo $result["acc_depos_id"]; ?>&temp1=<? echo $result["acct_id"]; ?>&temp2=<? echo $result4["acc_unit_id"]; ?>&temp3=<? echo $result2["acc_unit_redep_id"]; ?>&temp4=<? echo $result3["acc_unit_dep_id"]; ?>&temp5=<? echo $year; ?>"><? echo number_format($am1,2); ?></a><? } else {?> <a href="display_accdep_draw.php?temp=<? echo $result["acc_depos_id"]; ?>&temp1=<? echo $result["acct_id"]; ?>&temp2=<? echo $result4["acc_unit_id"]; ?>&temp3=<? echo $result2["acc_unit_redep_id"]; ?>&temp4=<? echo $result3["acc_unit_dep_id"]; ?>&temp5=<? echo $year; ?>"><? echo number_format($am1,2); ?><? } ?> </a></div></td>
</tr>
<? $sql4 = "select * from acc_deposit_draw where acc_depos_id ='$result[0]' and act_id='01' order by acc_depdraw_date asc";
$data8 = mysql_query($sql4);
$Num_Rows4 = mysql_num_rows($data8); //
$r_amount =0;
while($result8=mysql_fetch_array($data8)){
?>
<tr bgcolor="#ECF9FF">
<td height="24"> </td>
<td height="24"> </td>
<td height="24"> </td>
<td><div align="left" class="style16"> - <? echo เลขที่เอกสารถอนเงิน."::".$result8["acc_depdraw_doc"]?> </div></td>
<td> </td>
<td> </td>
<td><div align="right" class="style16"><? echo number_format($result8["acc_depdraw_amount"],2); $total_am+=$result8['acc_depdraw_amount']; ?> </div></td>
<td><div align="right" class="style16"><?
//$acc_am=$result["acc_rec_amount"];
$sql5 = "select * from acc_deposit,acc_deposit_draw where acc_deposit.acc_depos_id=acc_deposit_draw.acc_depos_id and acc_deposit_draw.acc_depos_id='$result8[4]' and acc_deposit_draw.acc_depdraw_id = '$result8[0]' ";
$data9 = mysql_query($sql5);
while($result9=mysql_fetch_array($data9)){
$depos_amount = $result9['acc_depos_amount'];
$depdraw_amount = $result9['acc_depdraw_amount'];
$r_amount-=$depdraw_amount;
//echo r_amount."=".$r_amount;
//$acc_am-=$ref_amount ;
//echo r_amount1."=".$r_amount1 -= $ref_amount;
$sql6 = "select * from acc_deposit,acc_deposit_draw where acc_deposit.acc_depos_id=acc_deposit_draw.acc_depos_id and acc_deposit_draw.acc_depos_id='$result9[0]' and acc_deposit_draw.acc_depdraw_id = '$result9[18]' ";
$data10 = mysql_query($sql6);
// echo $sql3;
//$result4=mysql_fetch_array($data3);
// $depo_amount = $result3['depo_amount'];
while($result10=mysql_fetch_array($data10)){
$depos_amount = $result10['acc_depos_amount'];
$depdraw_amount = $result10['acc_depdraw_amount'];
//echo r_amount."=".$r_amount;
//echo ref_amount."=".$ref_amount;
$am=$r_amount+$depos_amount;
echo number_format($am,2);
}
}
?> </div></td>
</tr>
<tr bgcolor="#CCEEFF">
<td height="24" colspan="5"><div align="center"><strong>รวม</strong></div></td>
<td><div align="right" class="style16"><? echo number_format($total_am1,2);?> </div></td>
<td><div align="right" class="style16"><? echo number_format($total_am,2);?> </div></td>
<td><div align="right" class="style16"><? $sum_total= $total_am1-$total_am; echo number_format($sum_total,2);?> </div></td>
</tr>
<?php }
}
$i++; }
?>
</tbody>
</table>
<p><br />
<? } ?>
<!-- end content --><br />
<br />
</div>
</div>
</body>
รบกวนด้วยนะคะ ขอบคุณมากๆเลยค่ะTag : PHP, MySQL
Date :
2012-11-12 14:26:35
By :
yeanz
View :
1979
Reply :
3
วิธีที่ง่ายที่สุดในความคิดผมคือ สร้าง table ขึ้นมาอีก table นึง แล้วเมื่อกด export ก้ให้ดึงข้อมูลที่จะ export จากหลายๆ table
ที่คุณต้องการจะ export มา Insert ลงที่ table นี้ table เดียว แล้วค่อย export ค่าจาก table ออกไปเปน PDF ตามที่คุณต้องการ
Date :
2012-11-12 15:08:57
By :
tongjaab
ดันๆๆๆ ช่วยหน่อยนะคะ ><"
Date :
2012-11-13 09:10:14
By :
yeanz
Load balance : Server 03