我這里有這段代碼。它的作用是:首先用戶必須提交一個(gè)index.html表格,這樣做意味著他必須用他的分?jǐn)?shù)完成所有輸入(例如 80/100 成績(jī))。之后用戶按下提交按鈕,如您所見,我必須//foreach statement在表格上顯示他們的信息。這很好用。但今天我還添加了一個(gè)按鈕,將此表格信息轉(zhuǎn)換為 document.xls(Excel) . 很確定我在將 php 變量從一個(gè)部分傳遞到另一個(gè) php 部分時(shí)做錯(cuò)了。此外,<table>必須介于兩者之間<body> </body>,而不是像echo <table>我所說的那樣,否則腳本無法正常工作?;旧衔蚁胍_的方法從第一個(gè) php 部分獲取變量$name $score1 $score2等并將它們放置到<td> <?php $name = $_SESSION['name']; ?>`` </td> <td> <?php $score = $_SESSION['score']; ?> </td> 所以這是我的代碼: <?php session_start();?><html><head></head></html><body><?phpfunction average(){$name = $_POST['name'];$score1 = $_POST['math'];$score2 = $_POST['chemistry'];$score3 = $_POST['history'];$score4 = $_POST['english'];$score5 = $_POST['language'];$score6 = $_POST['religious'];$score7 = $_POST['german'];$score8 = $_POST['physics'];$score9 = $_POST['latin'];$score10 = $_POST['french'];$score11 = $_POST['music'];$study = array( "Mathimatics"=> $score1, "Chemistry"=> $score2, "Histroy"=> $score3, "English"=> $score4, "Language"=> $score5, "Religious"=> $score6, "German"=> $score7, "Physics"=> $score8, "Latin"=> $score9, "French"=> $score10, "Music"=> $score11); $_SESSION['name'] = $name; $_SESSION['score1'] = $score1; //echo "<div>"; //echo "<table class=\'tableToExl\'>"; //echo " <th>Projects</th>"; //echo " <th>Score</th>"; //foreach ($study as $key=>$values){ //echo " <tr>"; //echo " <td>$key</td>"; //echo " <td>$values</td>"; //echo " </tr>"; //}} average();?> <table class="tableToExl" data-tableName="Test Table 1"> <th>Projects</th> <th>Score</th> <tr> <!-- For example i placed only the name of the student and the first Project--> <td> <?php $name = $_SESSION['name']; ?> </td> <td> <?php $score = $_SESSION['score']; ?> </td> </tr></table>任何建議我做錯(cuò)了什么?謝謝
1 回答

精慕HU
TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
嘗試:
<td> <?php echo $_SESSION['name']; ?> </td> <td> <?php echo $_SESSION['score']; ?> </td>
- 1 回答
- 0 關(guān)注
- 148 瀏覽
添加回答
舉報(bào)
0/150
提交
取消