|
|
|
ช่วยด้วยครับ คือผมมีข้อมูล ตัวอย่าง ดังนี้นะครับ และขอคำแนะนำด้วยครับ |
|
|
|
|
|
|
|
select sum(Total)as totalall from table ก็จะได้ผลรวมของยอด total
|
|
|
|
|
Date :
2011-04-04 10:34:43 |
By :
Pep_Fare |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมไม่ได้เก็บ Total ไว้ในฐานข้อมูลนะครับ
|
|
|
|
|
Date :
2011-04-04 10:36:08 |
By :
mac1626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total a + total b + total c + total d งี้เหรอคะ?
|
|
|
|
|
Date :
2011-04-04 12:03:35 |
By :
mzchewiize |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช่ครับ คือตอนนี้ Total[i] อยู่ใน array จะเอามารวมกันได้ยังครับ.. ขอบคุณครับ
|
|
|
|
|
Date :
2011-04-04 13:17:01 |
By :
mac1626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select sum(Amount*Price) as total from table
หรือ
Code (PHP)
$count=count($Total);//นับจำนวน array
for($i=0;$i<=$count;$i++)
{
$sum=$sum+$Total[$i];
}
|
ประวัติการแก้ไข 2011-04-04 13:36:46 2011-04-04 13:37:31 2011-04-04 13:37:55
|
|
|
|
Date :
2011-04-04 13:35:54 |
By :
Pep_Fare |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ จะลองดูนะครับ
|
|
|
|
|
Date :
2011-04-04 13:54:34 |
By :
mac1626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่เวิร์ค ครับ ขอบคุณครับ
|
|
|
|
|
Date :
2011-04-04 13:59:29 |
By :
mac1626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
Conn2DB();
mysql_query("set NAMES tis620");
mysql_query("set character_set_results=tis620");
mysql_query("set character_set_connection=tis620");
mysql_query("set character_set_client=tis620");
$strSQL = "SELECT *,w_inkput.pu_price FROM w_inkput ";
$strSQL .= "INNER JOIN v_printer ON v_printer.pn_id = w_inkput.pu_pid ";
$strSQL .= "LEFT JOIN z_department ON z_department.dpt_id = v_printer.pn_dpt_id ";
$strSQL .= "LEFT JOIN z_company ON z_company.cpn_id = z_department.cpn_id ";
$strSQL .= "";
$strSQL .= "";
$strSQL .= "WHERE month(pu_datep) ='$month1' and year(pu_datep) ='$year1'";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 35; // Per Page
$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;
}
$strSQL .=" order by pu_datep DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<form name="frmMain" action="phpMySQLDeleteMultiRecord.php" method="post" OnSubmit="return onDelete();">
<table class="reporttakeink">
<tr>
<td width="96" height="20" class="helpHed">Date</th>
<td width="231" height="20" class="helpHed"><div align="center">Printer.Name </div></td>
<td width="273" height="20" class="helpHed"><div align="center">Ink.Name</div></td>
<td width="102" height="20" class="helpHed"><div align="center">Price</div></td>
<td width="72" height="20" class="helpHed"><div align="center">Amount </div></td>
<td width="102" height="20" class="helpHed"><div align="center">Total</div></td>
<td width="242" height="20" class="helpHed"><div align="center">Department </div></td>
</tr>
<?php
$h=0;
while($objResult = mysql_fetch_array($objQuery))
{
$h++;
if($h%2==0)
{
$bg = "#E9E9E9";
}
else
{
$bg = "#FFFFFF";
}
$total = $objResult["pu_price"] * $objResult["pu_amount"];
?>
<tr bgcolor="<?=$bg;?>">
<td height="20"><div align="center"><?=$objResult["pu_datep"];?></div></td>
<td height="20"><div align="left"> <?=$objResult["pu_pname"];?><?php echo "$total";?></a></div></td>
<td height="20"><div align="left"> <?=$objResult["pu_inkname"];?></div></td>
<td height="20"><div align="right"><?=number_format($objResult["pu_price"],2);?> </div></td>
<td height="20"><div align="center"><?=$objResult["pu_amount"];?></div></td>
<td height="20"><div align="right"> <?php echo number_format("$total",2);?> </div></td>
<td height="20"><div align="left"> <?=$objResult["cpn_name"];?> <?=$objResult["dpt_name"];?></div></td>
</tr>
<?php
}
//$totalall = $total;
?>
<tr bgcolor="">
<td height="20" align="center"></td>
<td height="20" align="center"> </td>
<td height="20" align="center"></td>
<td height="20" align="center"></td>
<td height="20" align="center"><b>Total All</b></td>
<td height="20"><div align="right"> <b><?php echo number_format("$totalall",2);?></b> </div></td>
<td height="20"> </td>
</tr>
</table>
</form>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
}
CloseDB();
?>
</td>
</tr>
</table>
|
|
|
|
|
Date :
2011-04-04 14:40:18 |
By :
mac1626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$totalall = $totalall+$total;
เอาไว้ก่อนปิดวงเล็บ } ของ loop while ตรงบรรทัด 90 ค่ะ
|
|
|
|
|
Date :
2011-04-04 14:47:55 |
By :
Pep_Fare |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับ..
|
|
|
|
|
Date :
2011-04-04 14:50:47 |
By :
mac1626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|