|
|
|
สอบถามเรื่่อง...การหาผลรวมของจำนวนในแต่ละคอลัมภ์ต้องเขียนโค้ดยังไงค่ะ |
|
|
|
|
|
|
|
จากภาพต้องการหาผลรวมของ Total และ SumTotal ไว้บรรทัดท้ายสุด แต่ไม่รู้จะเขียนโค้ดยังไงอ่ะค่ะ รบกวนด้วยน่ะค่ะ ขอบคุณค่ะ
โค้ดที่เขียน
Code (PHP)
</head>
<body on id="manage_cost">
<div id="head_info">
<center>
<h1>รายงานสรุปข้อมูลการเช่าเครื่องคอมพิวเตอร์แยกตาม CenterNo.</h1></center>
</div>
<form name="frmSearch" method="get" action="<?=$_SERVER[SCRIPT_NAME];?>">
<table width="767" height="32" border="1">
<tr>
<th width="812" bgcolor="#CCCCCC">CenterNo.
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>">
<input type="submit" value="ค้นหา" ></th>
</tr>
</table>
<?php
$db = "../PCRental_App/DB/DB_PCRent.mdb" ; //ชื่อฐานข้อมูล MsAccess
$strConn = new COM("ADODB.Connection") or die("Cannot start ADO");
$strConn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath($db));
$strKeyword = $_GET["txtKeyword"];
$strSQL = "SELECT tb_Employee.PersonalNo, tb_Employee.Name_Surname, tb_Employee.Extension_No, tb_Employee.Email_Address, tb_Center.CenterNo, tb_Contract.Contract_No, tb_Function.Function_Name, tb_Equipment_Type.Equipment_Type, tb_Equipment.Act_Price, [Act_Replace]+[Act_New]+[Act_Replace_Contract] AS Total, [Total]*[Act_Price] AS SumTotal
FROM (tb_Function INNER JOIN ((tb_Employee INNER JOIN (tb_Center INNER JOIN tb_Center_Owner ON tb_Center.ID_Center = tb_Center_Owner.ID_Center) ON tb_Employee.PersonalNo = tb_Center_Owner.PersonalNo) INNER JOIN tb_Function_Emp ON tb_Employee.PersonalNo = tb_Function_Emp.PersonalNo) ON tb_Function.ID_Function = tb_Function_Emp.ID_Function) INNER JOIN ((tb_Equipment_Type INNER JOIN (tb_Contract INNER JOIN tb_Equipment ON tb_Contract.ID_Contract = tb_Equipment.ID_Contract) ON tb_Equipment_Type.ID_Equipment_Type = tb_Equipment.ID_Equipment_Type) INNER JOIN tb_Purchase ON tb_Equipment.ID_Equipment = tb_Purchase.ID_Equipment) ON tb_Function.ID_Function = tb_Purchase.ID_Function WHERE (tb_Center.CenterNo LIKE '%".$strKeyword."%' ) ";
$objRec = new COM("ADODB.Recordset");
$objRec->Open($strSQL, $strConn, 1,3);
if($objRec->EOF)
{
echo "Not found Record.";
}
else
{
$PageLen = 15;
$PageNo = $_GET["Page"];
if(!$PageNo)
{
$PageNo = 1;
}
$TotalRecord = $objRec->RecordCount();
$objRec->PageSize = $PageLen;
$TotalPage = $objRec->PageCount();
$objRec->AbsolutePage = $PageNo;
?>
<br>
<table width="99%" height="26" border="1">
<tr>
<td width="50%" bgcolor="#CCCCCC"><strong>CenterNumber : </strong> <?=$objRec->Fields["CenterNo"]->Value;?></td>
<td width="50%" bgcolor="#CCCCCC"><strong>FunctionName :</strong> <?=$objRec->Fields["Function_Name"]->Value;?></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><strong>UserContact :</strong> <?=$objRec->Fields["Name_Surname"]->Value;?></td>
<td bgcolor="#FFFFFF"><strong>PersonalNo :</strong> <?=$objRec->Fields["PersonalNo"]->Value;?></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Ext. :</strong> <?=$objRec->Fields["Extension_No"]->Value;?></td>
<td bgcolor="#CCCCCC"><strong>Email :</strong> <?=$objRec->Fields["Email_Address"]->Value;?></td>
</tr>
</table>
</form>
<table width="767" border="1">
<tr>
<th width="122" bgcolor="#CCCCCC"><div align="center">ContractNo.</div></th>
<th width="266" bgcolor="#CCCCCC"><div align="center">Type</div></th>
<th width="74" bgcolor="#CCCCCC"><div align="center">Total </div></th>
<th width="111" bgcolor="#CCCCCC"><div align="center">Unit/Price</div></th>
<th width="160" bgcolor="#CCCCCC"><div align="center">SumTotal </div></th>
</tr>
<?
While (!($objRec->EOF) and $No < $PageLen)
{
?>
<tr>
<td bgcolor="#FFFFFF"><?=$objRec->Fields["Contract_No"]->Value;?></td>
<td bgcolor="#FFFFFF"><?=$objRec->Fields["Equipment_Type"]->Value;?></td>
<td bgcolor="#FFFFFF"><div align="center"><?=$objRec->Fields["Total"]->Value;?></td>
<td bgcolor="#FFFFFF"><div align="center"><?=$objRec->Fields["Act_Price"]->Value;?></td>
<td bgcolor="#FFFFFF"><div align="center"><?=$objRec->Fields["SumTotal"]->Value;?></div></td>
</tr>
<?
$No = $No + 1;
$objRec->MoveNext();
}
?>
</table>
<br>
<?
}
$objRec->Close();
$strConn->Close();
$strConn = null;
?>
Total : <?=$TotalRecord?> Page <?=$PageNo?> All Page <?=$TotalPage?>
<? if($PageNo > 1){ ?>
<a href="<?=$_SERVER[SCRIPT_NAME];?>?txtKeyword=<?=$strKeyword;?>&Page=1"><< First</a>
<a href="<?=$_SERVER[SCRIPT_NAME];?>?txtKeyword=<?=$strKeyword;?>&Page=<?=$PageNo-1?>">< Back</a>
<? }?>
<? if($PageNo < $TotalPage) { ?>
<a href="<?=$_SERVER[SCRIPT_NAME];?>?txtKeyword=<?=$strKeyword;?>&Page=<?=$PageNo+1?>">Next ></a>
<a href="<?=$_SERVER[SCRIPT_NAME];?>?txtKeyword=<?=$strKeyword;?>&Page=<?=$TotalPage?>">Last >></a>
<?}?>
<br>
Go to
<? for($intID=1;$intID<=$TotalPage;$intID++){?>
<? if($intID == $PageNo){?>
<b><?=$intID?></b>
<?}else{?>
<a href="<?=$_SERVER[SCRIPT_NAME];?>?txtKeyword=<?=$strKeyword;?>&Page=<?=$intID?>"><?=$intID?></a>
<?}?>
<?}?>
</body>
</html>
Tag : PHP, Ms Access
|
ประวัติการแก้ไข 2012-10-15 09:18:44 2012-10-15 09:19:56
|
|
|
|
|
Date :
2012-10-15 09:16:49 |
By :
mah_comsci |
View :
1234 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
for($i=1;$i<10;$i++){
$total+=$i;
}
echo $total;
?>
ไม่ทราบว่าแบบนี้ได้ไหม ครับ
|
|
|
|
|
Date :
2012-10-15 10:29:56 |
By :
phong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณค่ะ จะลองทำดู
|
|
|
|
|
Date :
2012-10-15 14:11:19 |
By :
mah_comsci |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|