Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “回声正在输出”;0“;而不是桌子_Php_Database - Fatal编程技术网

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=”";$output='foobar'
或者在所有代码之上,设置
$output=''
$output .= "...";
$output .= <<<EOL
...
EOL;