有人可以帮助我从mysql表中获取数据。我想执行有关活动字段值的计算。 sql查询工作,但我无法在php页面中应用它。 非常感谢你,我刚刚更改了查询结构代码,它仍然无法正常工作,你会看到什么:
<?php
include_once('mysql_workbench.php');
$qryz="SELECT Agent, Activity, format((PreTaxSalary), 2) as PreTaxSalary,
format((TransactionNum), 2) as TransactionNum
CASE attr(Activity)
When 'Eligibility Only (DDS)'
Then
IF sum(TransactionNum)< 2206
Then sum(TransactionNum)*6.81
ElseIF sum(TransactionNum)< 2706
Then ((sum(TransactionNum)-2205)*6.95)+ (2205*6.81)
ElseIF sum(TransactionNum)< 3206
Then ((sum(TransactionNum)-2705)*7.25) + (500*6.95) + (2205*6.81)
Else ((sum(TransactionNum)-3205)*7.85)+ (500*7.25) + (500*6.95)
+(2205*6.81)
END
When 'EOB posting'
Then
IF sum(TransactionNum)< 1786
Then sum(TransactionNum)*8.41
ElseIF sum(TransactionNum)< 2786
Then ((sum(TransactionNum)-1785)*9)+ (1785*8.41)
ElseIF sum(TransactionNum)< 3786
Then ((sum(TransactionNum)-2785)*9.75) + (1000*9) + (1785*8.41)
Else ((sum(TransactionNum)-3785)*10.5)+ (1000*9.75) + (1000*9) +
(1785*8.41)
END
When 'Trainee-1'
Then AVG(PreTaxSalary)*sum(TransactionNum)
When 'Trainee-1'
Then AVG(PreTaxSalary)*sum(TransactionNum)
When 'Trainee-2'
Then AVG(PreTaxSalary)*sum(TransactionNum)
END
from payroll_trial group by Agent ";
?>
<tr>
<th >Agent</th>
<th >Activity</th>
<th >TransactionNum</th>
<th>PreTaxSalary</th>
</tr>
<?php
while($d=mysqli_fetch_array($resz))
{
?>
<td><?php echo $d['Agent'];?></td>
<td><?php echo $d['Client'];?></td>
<td><?php echo $d['TransactionNum'];?></td>
<td><?php echo $d['PreTaxSalary'];?> gdes </td>
</tr>
<?php
}
?>
答案 0 :(得分:0)
我认为你的代码最大的问题是它不是PHP:)
我建议先学习如何用PHP编写代码。
但如果您想直接使用PHP中的Mysql,本教程可以帮助您http://www.w3schools.com/php/php_mysql_intro.asp
答案 1 :(得分:0)
存储此代码的最佳方法是存储过程 https://dev.mysql.com/doc/refman/5.0/en/create-procedure.html
答案 2 :(得分:0)
我终于找到了办法:
<?php
include_once('mysql_workbench.php');
$qryz="SELECT Agent, Activity, PreTaxSalary as
PreT, SUM(TransactionNum) as totalTransaction from payroll_trial;
$resz = @mysqli_query($dbc, $qryz);
?>
<tr>
<th >Agent</th>
<th>Activity</th>
<th>Price</th>
<th>Amount</th>
<th>PreTaxSalary</th>
</tr>
<?php
while($d=mysqli_fetch_array($resz))
{
$total=$d['totalTransaction'];
switch($d['Activity'])
{
case 'Reverification(DOP)':
IF ($total < 1366)
$total= $total*11;
ElseIF ($total < 1866)
$total= (($total-1365)*11.65)+ (1365*11);
ElseIF ($total < 2366)
$total= (($total-1865)*13.2) + (500*11.65) + (1365*11);
Else
$total= (($total-2365)*13.8)+ (500*13.2) + (500*11.65)
+ (1365*11);
break;
case 'Medicaid (CS)':
IF ($total < 2731)
$total= $total*5.5;
ElseIF ($total < 1866)
$total= (($total-3231)*2730)+ (2730*5.5);
ElseIF ($total < 3731)
$total= (($total-3230)*6.8) + (500*6) + (2730*5.5) ;
Else
$total= (($total-3730)*7.2)+ (500*6.8) + (500*6) +
(2730*5.5);
break;
case 'Eligibility Only (DDS)':
IF ($total< 2206)
$total= $total*6.81;
ElseIF ($total< 2706)
$total= (($total-2205)*6.95)+ (2205*6.81);
ElseIF ($total < 3206)
$total= (($total-2705)*7.25) + (500*6.95) + (2205*6.81) ;
Else
$total= (($total-3205)*7.85)+ (500*7.25) +
(500*6.95) + (2205*6.81);
break;
?>
<tr>
<td><?php echo $d['Agent'];?></td>
<td><?php echo $d['Activity'];?></td>
<td><?php echo $d['totalTransaction '];?> </td>
</tr>
<td><?php echo $d['PreT'];?> </td>