title: redisplaying an echo and variable will mess up my table?
body: <p>What I want is the    <code>echo "&lt;p&gt;Average Mark: $average&lt;/p&gt;";</code> to appear above the table rather than below the table. If I do this though the problem is that it won't calculate the average as the echo is above the variable. But if I move the variable and with it the while loop above the whole table (I need the while loop to select the <code>$row[Mark]'</code> field from a query as that is the field that is going to be averaged), it messes up the structure of the table. How can I display the <code>$average, $total, $count</code> etc variables and  <code>echo "&lt;p&gt;Average Mark: $average&lt;/p&gt;";</code> above the table without messing up the table structure?</p>
  
  <p>I tried <code>$("#record").html(&lt;?php echo "Average Mark: $average"; ?&gt;);</code> but I get this error on this line:
  Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /web/stud/u0867587/Mobile_app/exam_grade_report.php on line 135</p>
  
  <p>Below is current code and you can see the <code>$count++; , $total += $row['Mark'];</code> in the while loop and the $average variable and echo at the bottom.</p>
  
  <pre><code>    &lt;?php
  
          $result = mysql_query($query);
          mysql_close();
  
         $("#record").html(&lt;?php echo "Average Mark: $average"; ?&gt;);
       ?&gt;
  &lt;div id="record"&gt;
      &lt;table border='1'&gt;
            &lt;tr&gt;
            &lt;th&gt;Session ID&lt;/th&gt;
            &lt;th&gt;TeacherUsername&lt;/th&gt;
            &lt;th&gt;Teacher Name&lt;/th&gt;
            &lt;th&gt;Module Number&lt;/th&gt;
            &lt;th&gt;Module Name&lt;/th&gt;
            &lt;th&gt;Course ID&lt;/th&gt;
            &lt;th&gt;Course Name&lt;/th&gt;
            &lt;th&gt;Year&lt;/th&gt;
            &lt;th&gt;Student Username&lt;/th&gt;
            &lt;th&gt;Student Name&lt;/th&gt;
            &lt;th&gt;Mark&lt;/th&gt;
            &lt;th&gt;Grade&lt;/th&gt;
            &lt;/tr&gt;
            &lt;?php
             $total = 0;
              $count = 0;
              while ($row = mysql_fetch_array($result)) {
              $count++;
                $total += $row['Mark'];
                echo "
            &lt;tr&gt;
            &lt;td&gt;{$row['SessionId']}&lt;/td&gt;
            &lt;td&gt;{$row['TeacherUsername']}&lt;/td&gt;
            &lt;td&gt;{$row['TeacherForename']} {$row['TeacherSurname']}&lt;/td&gt;
            &lt;td&gt;{$row['ModuleId']}&lt;/td&gt;
            &lt;td&gt;{$row['ModuleName']}&lt;/td&gt;
            &lt;td&gt;{$row['CourseId']}&lt;/td&gt;
            &lt;td&gt;{$row['CourseName']}&lt;/td&gt;
            &lt;td&gt;{$row['Year']}&lt;/td&gt;
            &lt;td&gt;{$row['StudentUsername']}&lt;/td&gt;
            &lt;td&gt;{$row['StudentForename']} {$row['StudentSurname']}&lt;/td&gt;
            &lt;td&gt;{$row['Mark']}&lt;/td&gt;
            &lt;td&gt;{$row['Grade']}&lt;/td&gt;
            &lt;/tr&gt;";
              }
              ?&gt;
  
              &lt;/table&gt;
          &lt;/div&gt;
          &lt;?php
          $average = (int)($total/$count);
          echo "&lt;p&gt;Average Mark: $average&lt;/p&gt;";
        ?&gt;
  </code></pre>