I am wondering if anyone can help? I am trying to output SQL in a table and I want to use functions 'slot' and 'groupnum' to modify the presentation of the output. When I try the code below the results are printing out in an unformatted way above the table rather than in it. Is there any fix for this?
// Table header.
echo '<table>
<tr><td><b>Time Slot</b></td>
<td><b>Group</b></td>
</tr>';
// Fetch and display the records:
while ($row9 = mysqli_fetch_array($result9, MYSQLI_ASSOC)) {
echo '<tr>
<td>' .slot ($row9['slotid']). '</td>
<td>' .groupnum($row9['groupid']). '</td>
</tr>';
}
echo '</table>'; // Close the table.
Is this working?
echo '<table>'; // Open the table
while ($row9 = mysqli_fetch_array($result9, MYSQLI_ASSOC)) {
echo '<tr>
<td><code>' . slot($row9['slotid']) . '</code></td>
<td><code>' .groupnum($row9['groupid']) . '</code></td>
</tr>';
}
echo '</table>'; // Close the table.
You have missed the opening tag of the table element.
echo '<table>'; // Open the table.
while ($row9 = mysqli_fetch_array($result9, MYSQLI_ASSOC)) {
echo '<tr>
<td>' .slot ($row9['slotid']). '</td>
<td>' .groupnum($row9['groupid']). '</td>
</tr>';
}
echo '</table>'; // Close the table.
The problem was that I was using an echo statement in the function rather than return, so the code above is okay. The problem was with the functions.
//Right way
function groupnum ($group){
return "Group $group";
}
//Wrong way
function groupnum ($group){
echo "Group $group";
}