我这里有这段代码。它的作用是:首先用户必须提交一个index.html表格,这样做意味着他必须用他的分数完成所有输入(例如 80/100 成绩)。之后用户按下提交按钮,如您所见,我必须//foreach statement在表格上显示他们的信息。这很好用。但今天我还添加了一个按钮,将此表格信息转换为 document.xls(Excel) . 很确定我在将 php 变量从一个部分传递到另一个 php 部分时做错了。此外,<table>必须介于两者之间<body> </body>,而不是像echo <table>我所说的那样,否则脚本无法正常工作。基本上我想要正确的方法从第一个 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>任何建议我做错了什么?谢谢
1 回答
精慕HU
TA贡献1845条经验 获得超8个赞
尝试:
<td> <?php echo $_SESSION['name']; ?> </td> <td> <?php echo $_SESSION['score']; ?> </td>
- 1 回答
- 0 关注
- 93 浏览
添加回答
举报
0/150
提交
取消