|
|
|
ช่วยดู Code หน่อยครับว่าทำไมถึง บวกลบตัวแปรไม่ได้ ทังๆที่ echo ตัวแปรออกมาดูแต่ละตัวก็มีค่า |
|
|
|
|
|
|
|
ช่วยดู Code หน่อยครับว่าทำไมถึง บวกลบตัวแปรไม่ได้ ทั้งๆที่ตัวแปรแต่ละตัว ลอง echo ออกมา ก็มีค่า แต่พอเอาตัวแปรมาลบกัน ค่าที่ออกมามันไม่ได้
Code (PHP)
<?
$_GET['SUMCREDIT'] = number_format($intTotal_Credit1,2);
$numd1 = $_GET['SUMDABIT'];
$numc1 = $_GET['SUMCREDIT'];
$a = $numc1+$numd1;
echo "$numd1<br />";
echo "$numc1<br />";
echo "$a";
?>
ค่าที่ได้
1,017,860.05
1,766,444.92
2
-----------------------------------------------------------------
Code php ทั้งหมดครับ
Code (PHP)
<?
if($_GET["dept"] != "")
{
$strSQL =
"SELECT
T2.AcctName,
sum(case month(T0.RefDate) when 1 then (T1.Debit -T1.credit) else 0 end) as 'd01',
sum(case month(T0.RefDate) when 2 then (T1.Debit -T1.credit) else 0 end) as 'd02',
sum(case month(T0.RefDate) when 3 then (T1.Debit -T1.credit) else 0 end) as 'd03',
sum(case month(T0.RefDate) when 4 then (T1.Debit -T1.credit) else 0 end) as 'd04',
sum(case month(T0.RefDate) when 5 then (T1.Debit -T1.credit) else 0 end) as 'd05',
sum(case month(T0.RefDate) when 6 then (T1.Debit -T1.credit) else 0 end) as 'd06',
sum(case month(T0.RefDate) when 7 then (T1.Debit -T1.credit) else 0 end) as 'd07',
sum(case month(T0.RefDate) when 8 then (T1.Debit -T1.credit) else 0 end) as 'd08',
sum(case month(T0.RefDate) when 9 then (T1.Debit -T1.credit) else 0 end) as 'd09',
sum(case month(T0.RefDate) when 10 then (T1.Debit -T1.credit) else 0 end) as 'd10',
sum(case month(T0.RefDate) when 11 then (T1.Debit -T1.credit) else 0 end) as 'd11',
sum(case month(T0.RefDate) when 12 then (T1.Debit -T1.credit) else 0 end) as 'd12'
FROM
OJDT T0
INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId
INNER JOIN OACT T2 ON T1.Account = T2.AcctCode
WHERE
(T2.segment_0 >= '510000000000' and T2.segment_0 <= '541048010000') and
(T2.segment_1 LIKE '%".$_GET["dept"]."%') AND
(year(T0.RefDate) LIKE '%".$_GET["year"]."%')
GROUP BY
T2.AcctName
ORDER BY T2.AcctName ASC";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="100%" border="1" align="center" cellspacing="0" bordercolor="#000000" bgcolor="#0033FF">
<tr bgcolor="#FF00FF">
<th width="18"><span class="style13">No.</span></th>
<th width="80"><span class="style13">Description</span></th>
<th width="60"><span class="style13">January</span></th>
<th width="60"><span class="style13">February</span></th>
<th width="60"><span class="style13">February</span></th>
<th width="60"><span class="style13">April</span></th>
<th width="60"><span class="style13">May</span></th>
<th width="60"><span class="style13">June</span></th>
<th width="60"><span class="style13">July</span></th>
<th width="60"><span class="style13">August</span></th>
<th width="60"><span class="style13">September</span></th>
<th width="60"><span class="style13">October</span></th>
<th width="60"><span class="style13">November</span></th>
<th width="60"><span class="style13">December</span></th>
</tr>
<?
$i=1;
$j=1;
$intTotal_Debit1 = 0;
$intTotal_Credit1 = 0;
$intTotal_Debit2 = 0;
$intTotal_Credit2 = 0;
$intTotal_Debit3 = 0;
$intTotal_Credit3 = 0;
$intTotal_Debit4 = 0;
$intTotal_Credit4 = 0;
$intTotal_Debit5 = 0;
$intTotal_Credit5 = 0;
$intTotal_Debit6 = 0;
$intTotal_Credit6 = 0;
$intTotal_Debit7 = 0;
$intTotal_Credit7 = 0;
$intTotal_Debit8 = 0;
$intTotal_Credit8 = 0;
$intTotal_Debit9 = 0;
$intTotal_Credit9 = 0;
$intTotal_Debit10 = 0;
$intTotal_Credit10 = 0;
$intTotal_Debit11 = 0;
$intTotal_Credit11 = 0;
$intTotal_Debit12 = 0;
$intTotal_Credit12 = 0;
while($objResult = mssql_fetch_array($objQuery))
//while($objResult = mssql_fetch_array($objQuery) && $objResult2 = mssql_fetch_array($objQuery2))
{
$intTotal_Debit1 = $intTotal_Debit1 + $objResult["d01"];
$intTotal_Credit1 = $intTotal_Credit1 + $objResult["c01"];
$intTotal_Debit2 = $intTotal_Debit2 + $objResult["d02"];
$intTotal_Credit2 = $intTotal_Credit2 + $objResult["c02"];
$intTotal_Debit3 = $intTotal_Debit3 + $objResult["d03"];
$intTotal_Credit3 = $intTotal_Credit3 + $objResult["c03"];
$intTotal_Debit4 = $intTotal_Debit4 + $objResult["d04"];
$intTotal_Credit4 = $intTotal_Credit4 + $objResult["c04"];
$intTotal_Debit5 = $intTotal_Debit5 + $objResult["d05"];
$intTotal_Credit5 = $intTotal_Credit5 + $objResult["c05"];
$intTotal_Debit6 = $intTotal_Debit6 + $objResult["d06"];
$intTotal_Credit6 = $intTotal_Credit6 + $objResult["c06"];
$intTotal_Debit7 = $intTotal_Debit7 + $objResult["d07"];
$intTotal_Credit7 = $intTotal_Credit7 + $objResult["c07"];
$intTotal_Debit8 = $intTotal_Debit8 + $objResult["d08"];
$intTotal_Credit8 = $intTotal_Credit8 + $objResult["c08"];
$intTotal_Debit9 = $intTotal_Debit9 + $objResult["d09"];
$intTotal_Credit9 = $intTotal_Credit9 + $objResult["c09"];
$intTotal_Debit10 = $intTotal_Debit10 + $objResult["d10"];
$intTotal_Credit10 = $intTotal_Credit10 + $objResult["c10"];
$intTotal_Debit11 = $intTotal_Debit11 + $objResult["d11"];
$intTotal_Credit11 = $intTotal_Credit11 + $objResult["c11"];
$intTotal_Debit12 = $intTotal_Debit12 + $objResult["d12"];
$intTotal_Credit12 = $intTotal_Credit12 + $objResult["c12"];
$j++;
if($j%2==0)
{
$bg = "#99CCFF";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center" class="style8">
<?=$i;?>
</div></td>
<!--<td><div align="left"><span class="style8"><?=$objResult["AcctCode"];?></span></div></td>-->
<td><span class="style8">
<?=$objResult["AcctName"];?>
</span></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d01"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d02"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d03"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d04"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d05"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d06"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d07"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d08"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d09"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d10"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d11"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["d12"],0,-4),2);?>
</span></div></td>
</tr>
<?
$i++;
}
?>
<tr bgcolor="#FFCC33">
<td colspan="2" nowrap="nowrap"><div align="center">ToTal</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit1,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit2,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit3,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit4,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit5,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit6,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit7,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit8,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit9,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit10,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit11,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Debit12,2);?>
</div></td>
</tr>
</table>
<? $_GET['SUMDABIT'] = number_format($intTotal_Debit1,2);?>
<br>
<?
mssql_close($objConnect);
}
?>
<?
if($_GET["dept"] != "")
{
$strSQL =
"SELECT
T2.AcctName,
sum(case month(T0.RefDate) when 1 then (T1.Credit-T1.Debit) else 0 end) as 'c01',
sum(case month(T0.RefDate) when 2 then (T1.Credit-T1.Debit) else 0 end) as 'c02',
sum(case month(T0.RefDate) when 3 then (T1.Credit-T1.Debit) else 0 end) as 'c03',
sum(case month(T0.RefDate) when 4 then (T1.Credit-T1.Debit) else 0 end) as 'c04',
sum(case month(T0.RefDate) when 5 then (T1.Credit-T1.Debit) else 0 end) as 'c05',
sum(case month(T0.RefDate) when 6 then (T1.Credit-T1.Debit) else 0 end) as 'c06',
sum(case month(T0.RefDate) when 7 then (T1.Credit-T1.Debit) else 0 end) as 'c07',
sum(case month(T0.RefDate) when 8 then (T1.Credit-T1.Debit) else 0 end) as 'c08',
sum(case month(T0.RefDate) when 9 then (T1.Credit-T1.Debit) else 0 end) as 'c09',
sum(case month(T0.RefDate) when 10 then (T1.Credit-T1.Debit) else 0 end) as 'c10',
sum(case month(T0.RefDate) when 11 then (T1.Credit-T1.Debit) else 0 end) as 'c11',
sum(case month(T0.RefDate) when 12 then (T1.Credit-T1.Debit) else 0 end) as 'c12'
FROM
OJDT T0
INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId
INNER JOIN OACT T2 ON T1.Account = T2.AcctCode
WHERE
(T2.segment_0 >= '410000000000' and T2.segment_0 <= '43100170000') and
(T2.segment_1 LIKE '%".$_GET["dept"]."%') AND
(year(T0.RefDate) LIKE '%".$_GET["year"]."%')
GROUP BY
T2.AcctName
ORDER BY T2.AcctName ASC";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="100%" border="1" align="center" cellspacing="0" bordercolor="#000000" bgcolor="#0033FF">
<tr bgcolor="#FF00FF">
<th width="18"><span class="style13">No.</span></th>
<th width="80"><span class="style13">Description</span></th>
<th width="60"><span class="style13">January</span></th>
<th width="60"><span class="style13">February</span></th>
<th width="60"><span class="style13">March</span></th>
<th width="60"><span class="style13">April</span></th>
<th width="60"><span class="style13">May</span></th>
<th width="60"><span class="style13">June</span></th>
<th width="60"><span class="style13">July</span></th>
<th width="60"><span class="style13">August</span></th>
<th width="60"><span class="style13">September</span></th>
<th width="60"><span class="style13">October</span></th>
<th width="60"><span class="style13">November</span></th>
<th width="60"><span class="style13">December</span></th>
</tr>
<?
$i=1;
$j=1;
$intTotal_Debit1 = 0;
$intTotal_Credit1 = 0;
$intTotal_Debit2 = 0;
$intTotal_Credit2 = 0;
$intTotal_Debit3 = 0;
$intTotal_Credit3 = 0;
$intTotal_Debit4 = 0;
$intTotal_Credit4 = 0;
$intTotal_Debit5 = 0;
$intTotal_Credit5 = 0;
$intTotal_Debit6 = 0;
$intTotal_Credit6 = 0;
$intTotal_Debit7 = 0;
$intTotal_Credit7 = 0;
$intTotal_Debit8 = 0;
$intTotal_Credit8 = 0;
$intTotal_Debit9 = 0;
$intTotal_Credit9 = 0;
$intTotal_Debit10 = 0;
$intTotal_Credit10 = 0;
$intTotal_Debit11 = 0;
$intTotal_Credit11 = 0;
$intTotal_Debit12 = 0;
$intTotal_Credit12 = 0;
while($objResult = mssql_fetch_array($objQuery))
//while($objResult = mssql_fetch_array($objQuery) && $objResult2 = mssql_fetch_array($objQuery2))
{
$intTotal_Debit1 = $intTotal_Debit1 + $objResult["d01"];
$intTotal_Credit1 = $intTotal_Credit1 + $objResult["c01"];
$intTotal_Debit2 = $intTotal_Debit2 + $objResult["d02"];
$intTotal_Credit2 = $intTotal_Credit2 + $objResult["c02"];
$intTotal_Debit3 = $intTotal_Debit3 + $objResult["d03"];
$intTotal_Credit3 = $intTotal_Credit3 + $objResult["c03"];
$intTotal_Debit4 = $intTotal_Debit4 + $objResult["d04"];
$intTotal_Credit4 = $intTotal_Credit4 + $objResult["c04"];
$intTotal_Debit5 = $intTotal_Debit5 + $objResult["d05"];
$intTotal_Credit5 = $intTotal_Credit5 + $objResult["c05"];
$intTotal_Debit6 = $intTotal_Debit6 + $objResult["d06"];
$intTotal_Credit6 = $intTotal_Credit6 + $objResult["c06"];
$intTotal_Debit7 = $intTotal_Debit7 + $objResult["d07"];
$intTotal_Credit7 = $intTotal_Credit7 + $objResult["c07"];
$intTotal_Debit8 = $intTotal_Debit8 + $objResult["d08"];
$intTotal_Credit8 = $intTotal_Credit8 + $objResult["c08"];
$intTotal_Debit9 = $intTotal_Debit9 + $objResult["d09"];
$intTotal_Credit9 = $intTotal_Credit9 + $objResult["c09"];
$intTotal_Debit10 = $intTotal_Debit10 + $objResult["d10"];
$intTotal_Credit10 = $intTotal_Credit10 + $objResult["c10"];
$intTotal_Debit11 = $intTotal_Debit11 + $objResult["d11"];
$intTotal_Credit11 = $intTotal_Credit11 + $objResult["c11"];
$intTotal_Debit12 = $intTotal_Debit12 + $objResult["d12"];
$intTotal_Credit12 = $intTotal_Credit12 + $objResult["c12"];
$j++;
if($j%2==0)
{
$bg = "#99CCFF";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center" class="style8">
<?=$i;?>
</div></td>
<!--<td><div align="left"><span class="style8"><?=$objResult["AcctCode"];?></span></div></td>-->
<td><span class="style8">
<?=$objResult["AcctName"];?>
</span></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c01"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c02"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c03"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c04"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c05"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c06"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c07"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c08"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c09"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c10"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c11"],0,-4),2);?>
</span></div></td>
<td><div align="right"><span class="style8">
<?=number_format(substr($objResult["c12"],0,-4),2);?>
</span></div></td>
</tr>
<?
$i++;
}
?>
<tr bgcolor="#FFCC33">
<td colspan="2" nowrap="nowrap"><div align="center">ToTal</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit1,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit2,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit3,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit4,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit5,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit6,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit7,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit8,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit9,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit10,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit11,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit12,2);?>
</div></td>
</tr>
<?
$_GET['SUMCREDIT'] = number_format($intTotal_Credit1,2);
$numd1 = $_GET['SUMDABIT'];
$numc1 = $_GET['SUMCREDIT'];
$a = $numc1+$numd1;
echo "$numd1<br />";
echo "$numc1<br />";
echo "$a";
?>
<tr bgcolor="#FFCC33">
<td colspan="2" nowrap="nowrap"><div align="center">ToTal</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<? echo $numd1;?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit2,2) - number_format($numd1,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit3,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit4,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit5,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit6,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit7,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit8,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit9,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit10,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit11,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_Credit12,2);?>
</div></td>
</tr>
</table>
<br>
<p><?
mssql_close($objConnect);
}
?>
Tag : PHP, Ms SQL Server 2005
|
|
|
|
|
|
Date :
2012-04-21 01:02:12 |
By :
karurub |
View :
1118 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
number_format เป็น Sting ฟังชั่นครับไม่สามารถคำนวนได้ต้องคำนวนเสร็จแล้วค่อย number_format ลองตัวอย่างครับ
Code (PHP)
<?php
$number_1 = 1000.20;
$number_2 = 1000.20;
$total = $number_1 + $number_2;
echo $total."<br>";
echo number_format($total,2);
?>
|
|
|
|
|
Date :
2012-04-21 01:26:34 |
By :
golfer4425 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|