I want to make a timetable in a HTML-table. I have a database structure set up and now I have trouble with displaying the database data in the HTML-table correctly.
My database structure involves:
The days are numbered by day_nr where 1 = monday, 2 = tuesday, 3 = wednesday, 4 = thursday and 5 = friday. The hours are numbered by hour_nr from 1 to 10.
Here is an example of what I eventually want to create.
Some code:
<?php
session_start();
// Connect MySQL Database
require("function.php");
$con = sql_connection();
// Select data from database (select the right table)
$result01 = mysqli_query("SELECT teacher_code, day_nr, hour_nr, subject_code, room_nr, class_code FROM `lesson`");
echo "<table class='table table-striped table-bordered student_table'>
<thead class='thead-inverse'>
<tr>
<th class='start_time'></th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
</thead>";
You need to create a data structure in your php program representing your time table.
Perhaps you should create an array with an element for each day. Each element of that top level array can itself contain an array, with an element for each time slot in the day.
Then each time slot element can contain an array, with an element for each item to represent in the time slot.
You can then populate this data structure as you retrieve your MySQL result set. You can then render it -- write it to HTML -- using PHP code.
Explaining how to create and use of data structure is, in my opinion, beyond the scope of what you should expect in a Stack Overflow answer.
You have just echoed your table. now you need to echo the actual element in your database for that: you might consider this
if($num = mysqli_num_rows($result01) > 1){
while($res=mysqli_fetch_assoc[$result01]){
echo "<tr><td>";
echo $res['name of your attribute in the database'];
echo "</td><td></tr>";
}
}