Properly Drawing Data from MySQL

Hello there
I get mysql den da data but all the datas are coming down, I want to get the dataset under that date every day, and also have some of the last words to help differentiate the color of the syllable? Please check the php codes below for help on how to get it. When I do, the data is sorted in subordinate.

<!DOCTYPE html>
<!--<html lang="en-CA" itemscope="itemscope" itemtype="WebPage - schema.org">-->

<head>

<title>Haftalık Program</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<?php
include("db.php");
?> 
<link rel="stylesheet" href="table.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body>

<!-- / College Timetable-->
<div class='tab'>
<table border='0' cellpadding='0' cellspacing='0'>
<tr class='days'>
<th align="center"><h3 align="center"><strong>PAZARTESİ</strong></h3></th> 
<th align="center"><h3 align="center"><strong>SALI</strong></h3></th> 
<th align="center"><h3 align="center"><strong>ÇARŞAMBA</strong></h3></th>
<th align="center"><h3 align="center"><strong>PERŞEMBE</strong></h3></th>
<th align="center"><h3 align="center"><strong>CUMA</strong></h3></th>
<th align="center"><h3 align="center"><strong>CUMARTESİ</strong></h3></th>
<th align="center"><h3 align="center"><strong>PAZAR</strong></h3></th>
</tr>


<?php 
$alpts=$bag->query("select * from fightclubplan where gun='Pazartesi' ORDER BY saat ASC")-> fetchAll(PDO::FETCH_ASSOC); foreach($alpts as $keypts){ ?> 

<tr>

<td class='cs240 orange' data-tooltip='<?php echo $keypts['ders']; ?>'>
<strong><h5 align="center"><?php echo $keypts['ders']; ?></h5></strong>
<p><strong><h5 align="center"><?php echo $keypts['saat']; ?> / <?php echo $keypts['saat1']; ?></h5></strong></p>
<a href="../../img/hizmetler/<?php echo $keypts['resim']; ?>" target="_blank"><center>
<img src="../../img/hizmetler/<?php echo $keypts['resim']; ?>" class="img-circle" width="80%"></center></a>
<?php } ?>

</td>
</tr>

<?php 
$alsal=$bag->query("select * from fightclubplan where gun='Salı' ORDER BY saat ASC")-> fetchAll(PDO::FETCH_ASSOC); foreach($alsal as $keysal){ ?> 
<tr>

<td class='cs335 blue lab' data-tooltip='<?php echo $keysal['ders']; ?>'>
<strong><h5 align="center"><?php echo $keysal['ders']; ?></h5></strong>
<p><strong><h5 align="center"><?php echo $keysal['saat']; ?> / <?php echo $keysal['saat1']; ?></h5></strong></p> 
<a href="../../img/hizmetler/<?php echo $keysal['resim']; ?>" target="_blank"><center>
<img src="../../img/hizmetler/<?php echo $keysal['resim']; ?>" width="80%"></center></a>
<hr size="30px"> 
<?php } ?>
</td></tr>





<?php 
$alcar=$bag->query("select * from fightclubplan where gun='Çarşamba' ORDER BY saat ASC")-> fetchAll(PDO::FETCH_ASSOC); foreach($alcar as $keycar){ ?> 


<td class='cs335 green' data-tooltip='<?php echo $keycar['ders']; ?>'>
<strong><h5 align="center"><?php echo $keycar['ders']; ?></h5></strong>
<p><strong><h5 align="center"><?php echo $keycar['saat']; ?> / <?php echo $keycar['saat1']; ?></h5></strong></p>
<a href="../../img/hizmetler/<?php echo $keycar['resim']; ?>" target="_blank"><center>
<img src="../../img/hizmetler/<?php echo $keycar['resim']; ?>" width="80%"></center></a>
<hr size="30px"> 

</td>


<?php } ?> 
</tr>
</table>

</div>


<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="wow.js"></script>

</body>
</html>

The main problem with your output is you are putting each day inside its own <tr>...</tr> table row in the output (except in the one place you didn’t put a new <tr>.)

To match the table heading you have produced, you would need to output all the days inside one <tr>...</tr>, with each day inside its own <td>...</td> table cell.

Next, you need to decide if all the times for each day will be inside one <td>...</td> table cell or if you are going to make a new <tr>...</tr> for each different time slot.

Lastly, you need to query for and retrieve all the data you want using one query. When you retrieve the data, you will pivot(index) it using both the day/gun time/saat values. The query and data retrieval code needs to come before the start of the html document. You would store the retrieved data in an appropriately named php array variable, then just loop over that variable inside the html document to produce the output. This will remove the database specific code from the html document and eliminate the repetition of code you have now in the html document.

would you please do my example

Well, since this is a school project, we try not to do homework for you.

But, @phdr explained your errors. If you want further help with tables, here is a site that explains how to work with them. You might want to read up on them and then ask more questions for us to help you with.
Tables

Sponsor our Newsletter | Privacy Policy | Terms of Service