Php “回声正在输出”;0“;而不是桌子
请看下面的代码:Php “回声正在输出”;0“;而不是桌子,php,database,Php,Database,请看下面的代码: <?php $output += " <table border='1'> <tr> <th>Session ID</th> <th>TeacherUsername</th> <th>Teacher Name</th> <th>Module Numbe
<?php
$output += "
<table border='1'>
<tr>
<th>Session ID</th>
<th>TeacherUsername</th>
<th>Teacher Name</th>
<th>Module Number</th>
<th>Module Name</th>
<th>Course ID</th>
<th>Course Name</th>
<th>Year</th>
<th>Student Username</th>
<th>Student Name</th>
<th>Mark</th>
<th>Grade</th>
</tr>
";
$total = 0;
$count = 0;
while ($row = mysql_fetch_array($result)) {
$count++;
$total += $row['Mark'];
$output += "
<tr>
<td>{$row['SessionId']}</td>
<td>{$row['TeacherUsername']}</td>
<td>{$row['TeacherForename']} {$row['TeacherSurname']}</td>
<td>{$row['ModuleId']}</td>
<td>{$row['ModuleName']}</td>
<td>{$row['CourseId']}</td>
<td>{$row['CourseName']}</td>
<td>{$row['Year']}</td>
<td>{$row['StudentUsername']}</td>
<td>{$row['StudentForename']} {$row['StudentSurname']}</td>
<td>{$row['Mark']}</td>
<td>{$row['Grade']}</td>
</tr>";
}
$output += " </table>";
$average = (int)($total/$count);
echo "<p>Average Mark: $average</p>";
echo $output;
?>
您正在连接JavaScript样式。你想要:
$output = '';
$output .= 'foobar';
不要使用javascript,还要使用php的点
$output .=
但在使用=
之前,还必须先定义$output
因此,结果是:
<?php
$output = "";
$output .= "
<table border='1'>
<tr>
<th>Session ID</th>
<th>TeacherUsername</th>
<th>Teacher Name</th>
<th>Module Number</th>
<th>Module Name</th>
<th>Course ID</th>
<th>Course Name</th>
<th>Year</th>
<th>Student Username</th>
<th>Student Name</th>
<th>Mark</th>
<th>Grade</th>
</tr>
";
$total = 0;
$count = 0;
while ($row = mysql_fetch_array($result)) {
$count++;
$total .= $row['Mark'];
$output .= "
<tr>
<td>{$row['SessionId']}</td>
<td>{$row['TeacherUsername']}</td>
<td>{$row['TeacherForename']} {$row['TeacherSurname']}</td>
<td>{$row['ModuleId']}</td>
<td>{$row['ModuleName']}</td>
<td>{$row['CourseId']}</td>
<td>{$row['CourseName']}</td>
<td>{$row['Year']}</td>
<td>{$row['StudentUsername']}</td>
<td>{$row['StudentForename']} {$row['StudentSurname']}</td>
<td>{$row['Mark']}</td>
<td>{$row['Grade']}</td>
</tr>";
}
$output .= " </table>";
$average = (int)($total/$count);
echo "<p>Average Mark: $average</p>";
echo $output;
?>
$output+=“…”
在做加法,而不是浓缩。您正在向一个数字添加一个字符串,因此PHP尽可能将字符串转换为一个数字,结果可能是0
试一试
相反。或者更好的方法是使用:
$output.=使用+=
将尝试添加字符串的“值”,而不是在PHP中连接它
改用=
。你的答案和其他人的一样。搜索复选标记会让你看起来很傻。它起作用了,但出于一些奇怪的原因,它说:注意:未定义的变量:151行/web/stud/u0867587/Mobile_app/exam_grade_report.php中的输出。这一行在输出变量的末尾有“为什么会这样说?”@AlienWebguy:我得到的唯一答案是OP的评论。我已经删除了我写的评论posted@MayurPatel:使用前定义$output.=如图所示$output=”";我真的不在乎。这没那么重要,但出于某种奇怪的原因,它说:注意:未定义的变量:第151行的/web/stud/u0867587/Mobile_app/exam_grade_report.php中的输出。这是它的行“在输出变量的末尾。为什么这样说?它工作了,但出于一些奇怪的原因,它说:注意:未定义的变量:在第151行的/web/stud/u0867587/Mobile_app/exam_grade_report.php中输出。这是它的行”;在输出变量的末尾。为什么会这样说?因为你试图连接一个尚未设置的变量。将第一个更改为$output='foobar'
或者在所有代码之上,设置$output=''代码>
$output .= "...";
$output .= <<<EOL
...
EOL;