I'm making a simple PHP timetabling website. I've made a table and I have the times in a horizontal header and just Monday at the moment but i want to add 5 days, Monday to Friday. I'm just unsure of how to put the correct data in the correct times and day.
My database has id, name, startTime, endTime and Day
Some data could be 0, Basketball, 9:15, 10:15, Mon.
1, Tennis, 10:15, 11:15, Mon.
2, Cricket, 11:15, 12:15 Tue.
I currently have a while loop that can fill in the table, but not in the correct slots (td).
Here is my table code so far:
<?php
$host = 'localhost';
$user = 'root';
$pass = '******';
$db = 'test';
$error = 'Error Connecting to database';
$error1 = 'Error Selecting to database';
$connect = mysql_connect($host,$user,$pass) or die($error);
$select_db = mysql_select_db($db) or die($error1);
?>
<table border="1px">
<tr>
<div class="differentLine">
<th > </th>
<th > 9:15 - 10:15 </th>
<th > 10:15 - 11:15 </th>
<th > 11:15 - 12:15 </th>
<th > 12:15 - 13:15 </th>
<th > 13:15 - 14:15 </th>
<th > 14:15 - 15:15 </th>
<th > 15:15 - 16:15 </th>
<th > 16:15 - 17:15 </th>
<th > 17:15 - 18:15 </th>
</div>
</tr >
<tr>
<th >Monday </th>
<?php
$sqlip = "Select * From Modules";
$query = mysql_query($sqlip) or die("Error");
while($row = mysql_fetch_array($query))
{
$name = $row['Name'];
$day = $row['Day'];
$start_time = $row['Start_Time'];
$End_Time = $row['End_Time'];
if($start_time == "9:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "10:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "11:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "12:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "13:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "14:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "15:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "16:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
if($start_time == "17:15"){
echo"<td> $name2</td>";
} else {
echo"<td> </td>";
}
echo "</tr>";
}
?>
Aucun commentaire:
Enregistrer un commentaire