2015-10-24 148 views
-1

有人可以幫我請從MySQL表中抓取數據。我想執行有關活動字段值的計算。 SQL查詢工作,但我不能應用它在PHP頁面。 謝謝你這麼多,我只是改變了查詢結構代碼,但它仍然無法正常工作,什麼也看喲:執行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

你爲什麼把'sql'代碼放在php部分?把你的sql'CASE,IF ...'放到你的sql查詢中'SELECT Agent,...' – Alex

回答

0

嗯,我想你的代碼的最大問題是,它不是PHP :)

我會建議學習如何在PHP中編碼。

,但如果你想直接跳轉到PHP中使用MySQL這個教程可以幫助您http://www.w3schools.com/php/php_mysql_intro.asp

+0

你可以放棄一行不是PHP的行嗎? –

+0

該代碼已被編輯30分鐘前...查看原始版本。 –

+0

登記入住:糟糕,我應該看過。 –

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>