I'm having a problem when getting data from the database and outputting it into a table. The data comes out but its not positioned properly, I have looked at my code an cannot see where I have gone wrong. Any help is appreciated.

![if ($result->num_rows > 0) {
			echo "<table> <tr><th>First Name</th><th>Last Name</th><th>Course</th><th>Grade Code</th><th>Grade Percentage</th></tr";
			while($row = $result->fetch_assoc()) {
				echo "<tr><td>".$row["studentfname"]."</td><td>".$row["studentlname"]."</td><td>".$row["course"]."</td></tr>".$row["gradecode"]."</td><td>".$row["gradep"]."</td></tr>";]

(https://imgur.com/8AjiRv4)

    In the code you posted, you left out the final > character of the closing </tr> tag for the column headers.

      PS: Also, you have a </tr> tag in the data row where you want a <td> tag. It might help to break up the lines and do some indenting so that some of those things are easier to see, something like:

      if ($result->num_rows > 0) {
        echo "
      <table>
        <tr>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Course</th>
          <th>Grade Code</th>
          <th>Grade Percentage</th>
        </tr>";
        while ($row = $result->fetch_assoc()) {
          echo "
        <tr>
          <td>" . $row["studentfname"] . "</td>
          <td>" . $row["studentlname"] . "</td>
          <td>" . $row["course"]       . "</td>
          <td>" . $row["gradecode"]    . "</td>
          <td>" . $row["gradep"]       . "</td>
        </tr>";
        }
      }
      
      Write a Reply...