Hi all,
I'm new to the site and to PHP so if I'm asking somthing simple sorry and by the way I'm following a book at the moment so if my code is sloppy sorry.
I want to emulate a Excel workbook that is used to list scheduled training dates and comments for trainers in the following layout.
| Trainer | Trainer |
| Date | Date |
| Comments | Comments |
I've got two tables linked by trainer.id I want to display a table with the trainer's ID across the first row of the table and then get the linked schedule data for each trainer to display in a column below the row for each trainer.
I've two queries the first extracts the id's for each trainer from the trainer table and the second extracts the date and comments from the schedule table
Try as I might I can't get the data to link to the correct columns it just creates rows under the first column.
Any help greatly appricated.
Here's my code
<?php
@ $db = new mysqli('localhost', '*******', '*****', 'test');
/* check connection */
if (mysqli_connect_errno()) {
echo 'Sorry cant connect to the database';
exit();
}
else
echo 'connected';
$query="SELECT id FROM trainer";
$result=$db->query($query);
echo '<p>Number of records:';
echo $result->num_rows;
echo '</p>';
$query2="SELECT s.Sdate, s.Comments from Scheule s, trainer t where s.trainer = t.id ORDER BY Sdate ";
$result2=$db->query($query2);
echo '<p>Number of records:';
echo $result2->num_rows;
echo '</p>';
if ($result->num_rows)
{
echo '<table border="2">';
echo '<tr>';
while ($row = $result->fetch_assoc())
{
echo '<th>';
echo $row['id'];
echo '</th>';
}
echo '</tr>';
if ($result2->num_rows)
{
while ($row2 = $result2->fetch_assoc())
{
echo '<tr>';
echo '<td>';
echo $row2["Sdate"];
echo '<br/>';
echo $row2["Comments"];
echo '</td>';
echo '</tr>';
}
echo '</table>';
}
}
$result->free();
$result2->free();
$db->close();
?>