各位前輩好,是否有方法,可以在PHP裡利用javascript下拉試選單,運算後的值即時顯示在php的表格裡呢?
假如只要使用者下拉為(管理),PHP表格就呈現以下管理的值呢?
以下是php表格,填入以下MYSQL抓的值填入
echo "<div id='DIV_BIG'width='120px' height='120px'>";
echo "<table border=1>";
echo "<Tr>";
echo "<Td colspan='3' align='center' >";
echo "管理";
echo "</Td>";
echo "</Tr>";
echo"<Tr>";
echo"<Td style='width:50px' height='10px'>A+</Td>";
echo"<Td style='width:50px' height='10px'>$row1000[0]</Td>";
echo"<Td style='width:50px' height='10px'>$test1%</Td>";
echo"</Tr>";
echo"<Tr>";
echo"<Td style='width:50px' height='10px'>A</Td>";
echo"<Td style='width:50px' height='10px'>$row1001[0]</Td>";
echo"<Td style='width:50px' height='10px'>$test2%</Td>";
echo"</Tr>";
echo"<Tr>";
echo"<Td style='width:50px' height='10px'>A-</Td>";
echo"<Td style='width:50px' height='10px'>$row1002[0]</Td>";
echo"<Td style='width:50px' height='10px'>$test3%</Td>";
echo"</Tr>";
echo"<Tr>";
echo"<Td style='width:50px' height='10px'>B</Td>";
echo"<Td style='width:50px' height='10px'>$row1003[0]</Td>";
echo"<Td style='width:50px' height='10px'>$test4%</Td>";
echo"</Tr>";
echo "</Table>";
echo "</DIV>";
以下是php抓MYSQL的值,以及運算
//管理
$result1000=mysql_query("SELECT COUNT(grade) FROM approved where status = '1' and affiliation = '管' and grade = 'A+' and season ='$ha1'");
$row1000 = mysql_fetch_row($result1000);
$result1001=mysql_query("SELECT COUNT(grade) FROM approved where status = '1' and affiliation = '管' and grade = 'A' and season ='$ha1'");
$row1001 = mysql_fetch_row($result1001);
$result1002=mysql_query("SELECT COUNT(grade) FROM approved where status = '1' and affiliation = '管' and grade = 'A-' and season ='$ha1'");
$row1002 = mysql_fetch_row($result1002);
$result1003=mysql_query("SELECT COUNT(grade) FROM approved where status = '1' and affiliation = '管' and grade = 'B' and season ='$ha1'");
$row1003 = mysql_fetch_row($result1003);
$test1 = ($row1000[0] / ($row1000[0] + $row1001[0] + $row1002[0] +$row1003[0])*100);//A+計算幾成
$test2 = ($row1001[0] / ($row1000[0] + $row1001[0] + $row1002[0] +$row1003[0])*100);//A計算幾成
$test3 = ($row1002[0] / ($row1000[0] + $row1001[0] + $row1002[0] +$row1003[0])*100);//A-計算幾成
$test4 = ($row1003[0] / ($row1000[0] + $row1001[0] + $row1002[0] +$row1003[0])*100);//B計算幾成
需要的話,請參考以下範例
http://m3fu0.blogspot.com/2011/06/jquery.html
另外幫你改一下,免得再被笑echo
<div id='DIV_BIG'width='120px' height='120px'>
<table style="border:1px solid black">
<tr><td colspan='3' align='center'>管理</td></tr>
<?php
$ary = array('A+' => $row1000[0], 'A' => $row1001[0], 'A-' => $row1002[0], 'B' => $row1003[0]);
$i = 1;
foreach($ary as $key => $value){
echo"<tr><td style='width:50px' height='10px'>$key</td>";
echo"<td style='width:50px' height='10px'>$value</td>";
echo"<td style='width:50px' height='10px'>${test.$i}%</td></tr>";
$i++;
}
?>
</table>
</div>