<?php
include 'dbconnection.php';
$Days=0; $Kg=0.00; $Wage=0.00;
$Rate=0.00; $KgDivDays=0.00; $ExtraKgs = 0.00;
$WageExtraKgs=0.00; $TotalWages=0.00;
$BalanceWage=0.00; $EightPerc=0.00; $TwelvePerc=0.00; $ThreePerc=0.00;
$Advances=0.00; $FestAdvances=0.00;
//execute the SQL query and return records
$result = mysql_query("SELECT EmployeeName,DailyRate FROM employees");
//fetch the data from the database
try{
$i = 0;
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row{'EmployeeName'}."</td>";
$Rate=$row{'DailyRate'};
//echo "<td>".$Rate."</td>";
//echo "<td style = 'display:none'>".$row{'DailyRate'}."</td>";
//echo $Rate;
echo "<td><input type='text' name='Days' id='Days".$i."' onChange='CalcWage(".$i.");'/></td>";
echo "<td id='Wage".$i."'>".$Wage."</td>";
echo "<td><input type='text' name='Kg' id='Kg".$i."' onChange='CalcAmount(".$i.");'/></td>";
echo "<td id='KgDivDays".$i."'>".$KgDivDays."</td>";
echo "<td id='ExtraKgs".$i."'>".$ExtraKgs."</td>";
echo "<td id='WageExtraKgs".$i."'>".$WageExtraKgs."</td>";
echo "<td id='TotalWages".$i."'>".$TotalWages."</td>";
echo "<td id='EightPerc".$i."'>".$EightPerc."</td>";
echo "<td id='TwelvePerc".$i."'>".$TwelvePerc."</td>";
echo "<td id='ThreePerc".$i."'>".$ThreePerc."</td>";
echo "<td><input type='text' name='Advances' id='Advances".$i."'/></td>";
echo "<td><input type='text' name='FestAdvances' id='FestAdvances".$i."' onChange='CalcBalanceWage(".$i.");'/></td>";
echo "<td id='BalanceWage".$i."'>".$BalanceWage."</td>";
$i++;
}
}
catch(Exception $e)
{echo "error".$e;}
?>
<script type="text/javascript">
function CalcWage(i){
var Days=document.getElementById('Days'+i).value;
var php_rate = "<?php echo $Rate; ?>";
//alert(php_rate);
var Wage=parseFloat(Days*php_rate);
document.getElementById('Wage'+i).innerHTML= Wage;
return Wage;
}
function CalcAmount(i){
var Kg=document.getElementById('Kg'+i).value;
var Days=document.getElementById('Days'+i).value;
var KgDivDays = parseFloat(Days*4);
document.getElementById('KgDivDays'+i).innerHTML= KgDivDays;
var ExtraKgs=Kg-KgDivDays;
document.getElementById('ExtraKgs'+i).innerHTML= ExtraKgs;
var WageExtraKgs=ExtraKgs*50;
document.getElementById('WageExtraKgs'+i).innerHTML= WageExtraKgs;
var BasicSal = CalcWage(i);
var TotalWages= BasicSal + WageExtraKgs;
document.getElementById('TotalWages'+i).innerHTML= TotalWages;
var EightPerc= parseFloat(BasicSal * 0.08);
document.getElementById('EightPerc'+i).innerHTML= EightPerc;
var TwelvePerc= parseFloat(BasicSal * 0.12);
document.getElementById('TwelvePerc'+i).innerHTML= TwelvePerc;
var ThreePerc= parseFloat(BasicSal * 0.03);
document.getElementById('ThreePerc'+i).innerHTML= ThreePerc;
return TotalWages;
}
function CalcBalanceWage(i){
var Advances=parseFloat(document.getElementById('Advances'+i).value);
var FestAdvances=parseFloat(document.getElementById('FestAdvances'+i).value);
var TotWage = CalcAmount(i);
var BasSal = CalcWage(i);
var Deductions = parseFloat(Advances+FestAdvances+(BasSal*0.08));
var BalanceWage=parseFloat(TotWage-Deductions);
document.getElementById('BalanceWage'+i).innerHTML= BalanceWage;
return BalanceWage;
}
</script>
<?php
//close the connection
mysql_close($dbhandle);
?>
问题:我有一个员工数据库表,在这里我正在查询以获取员工姓名和他们各自的每日工资。在我的表中,我为 3 名员工提供了 500、600 和 600 的每日费率。当我在我的 while 循环中回显相应的费率时,它会针对每个员工显示正确的值。但是,当我乘以天数时,它似乎总是乘以 600(尽管我的数据库中的第一个值是 500)。感谢您能指出我哪里出错了。