iT邦幫忙

0

PHP利用javascript下拉試選單即時顯示問題!!!

各位前輩好,是否有方法,可以在PHP裡利用javascript下拉試選單,運算後的值即時顯示在php的表格裡呢?
假如只要使用者下拉為(管理),PHP表格就呈現以下管理的值呢?
https://ithelp.ithome.com.tw/upload/images/20180629/20089833GO2a50iw1K.jpg
https://ithelp.ithome.com.tw/upload/images/20180629/20089833SLu38dounc.jpg
以下是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計算幾成
看更多先前的討論...收起先前的討論...
froce iT邦研究生 4 級 ‧ 2018-06-29 20:11:16 檢舉
AJAX,結案。
jerry00218 iT邦研究生 1 級 ‧ 2018-06-30 00:27:53 檢舉
AJAX,附議
aj……不!我想先說的是為什麼要搞那麼多echo呢?
請善用認知「html即php樣板本身」這件事。
froce iT邦研究生 4 級 ‧ 2018-07-01 20:52:55 檢舉
也蠻佩服的,要我寫那麼多echo我還真的寫不出來。
小哈 iT邦新手 4 級 ‧ 2018-07-02 00:27:45 檢舉
前輩們,因為那個表格只能特定USER能看到,我才會用ECHO...
小哈 iT邦新手 4 級 ‧ 2018-07-02 11:45:19 檢舉
前輩們,小弟已經用前輩們建議的AJAX,去處理~感謝https://www.w3schools.com/php/php_ajax_xml.asp

1 個回答

0
kksugsay
iT邦新手 1 級 ‧ 2018-06-30 06:54:49

需要的話,請參考以下範例
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>

我要發表回答

立即登入回答