Good day everybody,
I'm here to ask for advices concerning schedule I've been working on.
The schedule should register each subject in each hour of each day from monday to friday. The problem I encouter is in the number of queries, because it needs to be different query for each hour of each day and that would give me 45 different queries(the difference will be in the variable for $day
and $hour
).
Of course I could make 45 different queries but that seems like insanity to me so I wonder, there has to be a way how to make the process simplier. I'm pretty sure, that the sollution is hidden in the for
or while
loops, but than again, I would need to change the variables in the process.
Now my table and most of my php looks like this (yes I'm missing the the part, where I extract the results to each row, that will be added later):
.table{
border: 1px solid red;
margin-left: auto;
margin-right:auto;
}
.table tr{
border: 1px solid blue;
}
.table td{
border: 1px solid green;
}
<?php
//authentication check
if (isset($_SESSION['authenticated'])) {
echo " User id: " . $ID;
require_once ('./functions/database.php');
$mon = 'monday';
$tue = 'tuesday';
$wen = 'wensday';
$thu = 'thursday';
$fri = 'friday';
$hourOne = '1.hour';
$hourTwo = '2.hour';
$hourThree = '3.hour';
$hourFour = '4.hour';
$hourFive = '5.hour';
$hourSix = '6.hour';
$hourSeven = '7.hour';
$hourEight = '8.houra';
$hournine = '9.hour';
$query1 = "select subject from student_subjects natural join subjects
where id_student = '$ID' AND day = '$mon' AND hour ='$hourOne';";
$result = mysqli_query($conn, $query);
echo "<section>";
echo "<table class='table'>
<tr>
<td>Den</td>
<td>1.hour</td>
<td>2.hour</td>
<td>3.hour</td>
<td>4.hour</td>
<td>5.hour</td>
<td>6.hour</td>
<td>7.hour</td>
<td>8.hour</td>
<td>9.hour</td>
</tr>
<tr>
<td>monday</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
</tr>
<tr>
<td>tuesday</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
</tr>
<tr>
<td>wensday</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
</tr>
<tr>
<td>thursday</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
</tr>
<tr>
<td>friday</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
<td>/*hodina*/</td>
</tr>
</table>";
echo "</section>";
} else {
echo " To see your schedule, you need to login first";
}
?>
(hodina = hour)
Thank you in advance for any advice.
</div>