# View attendance table by date in php mysql

**URL:** <https://www.phphelp.com/t/view-attendance-table-by-date-in-php-mysql/35543>\
**Category:** General PHP Help\
**Created:** [July 18, 2023, 6:06pm UTC](https://www.phphelp.com/t/view-attendance-table-by-date-in-php-mysql/35543 "2023-07-18T18:06:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![enarco](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@enarco](https://www.phphelp.com/u/enarco)\
**Post date:** [July 18, 2023, 6:06pm UTC](https://www.phphelp.com/t/view-attendance-table-by-date-in-php-mysql/35543/1 "2023-07-18T18:06:24Z")

</div>

Hi, I am trying to create a attendance system which displays of student if it came or not, by date.  
Thank you very much in advance

 ![resim_2023-07-18_205246006](https://www.phphelp.com/uploads/default/original/2X/d/d4eb535e66ed6d3af65aa4e386b015fa24f22a0d.png)

 ![resim_2023-07-18_210608272](https://www.phphelp.com/uploads/default/original/2X/2/2aa8a7cd5da7a22e582c4135fd512e53c9d5eb9b.png)

```auto
			<?php

				
				$t=time();
			

				if(isset($_GET['submit']) && !empty($_GET['sdate']) && !empty($_GET['edate']) && ($_GET['edate'] > $_GET['sdate']) 
				&& ($_GET['sdate']<$t) && ($_GET['edate']<$t))
				{
					$sdat = $_GET['sdate'];
					$edat= $_GET['edate'];

					
					$sdate = strtotime($sdat);
					
					$edate = strtotime($edat);
					
				
				if(($sdate<$t) && ($edate<=$t) && ($edate >= $sdate))
				{
					
				
					$query_student = "
					SELECT * from yaz_okulu_2023 JOIN yaz_okulu_2023_devamsizlik 
					WHERE yaz_okulu_2023.id = yaz_okulu_2023_devamsizlik.postId 
				
					";
					$stu=$conn->query($query_student);
					$rstu=$stu->fetchAll(PDO::FETCH_ASSOC);
				
					echo "<table class='table table-striped table-hover reports-table'>";
					echo "<thead>";
					echo "<tr>";
					echo "<th>kayıt no</th>";
					echo "<th>adi soyadi</th>";
					for($k=$sdate;$k<=$edate;$k=$k+86400)
					{
						$thisDate = date( 'd-m-Y', $k );
						$weekday= date("l", $k );
						$normalized_weekday = strtolower($weekday);
						if(($normalized_weekday="saturday") && ($normalized_weekday="sunday"))
						{
							echo "<th>".$thisDate."</th>";
						}
					}
					echo "<th></th>";
					echo "<th></th>";;
					echo "</tr>";
					echo "</thead>";
					echo "</tbody>";
					for($i=0;$i<count($rstu);$i++)
					{
					
						$present=0;
						$absent=0;
						$totlec=0;
						$perc=0;
						echo"<tr><td><h6>".$rstu[$i]['postId']."</h6></td>";
						echo "<td><h5>".$rstu[$i]['ogr_adi_soyadi']."</h5></td>";
						$dsid=$rstu[$i]['postId'];
						
						for($j=$sdate;$j<=$edate;$j=$j+86400)
						{
							 
				
							$weekday= date("l", $j );
							$currentDate = date('Y-m-d', $j);
							$normalized_weekday = strtolower($weekday);
							 if(($normalized_weekday="saturday") && ($normalized_weekday="sunday"))
							 {

								 $sql = "SELECT * from yaz_okulu_2023 JOIN yaz_okulu_2023_devamsizlik 
					WHERE yaz_okulu_2023.id =$dsid AND yaz_okulu_2023_devamsizlik.geldi_tarihi=$j " ;
								$stmt = $conn->prepare($sql); 
								$stmt->execute();
								$result = $stmt->fetchAll(PDO::FETCH_ASSOC); 
								if(!empty($result)){
								
									$totlec++;
									if($result[0]['yaz_okulu_2023_devamsizlik.geldi_mi']==1)
									{
										$present++;
										echo"<td><span class='text-success'>Yes</span></td>";
									}
									else
									{
										echo"<td><span class='text-danger'>No</span></td>";
										$absent++;
									}
								}
							
							}
						}
						
						echo"</tr>";
						
					}		
					echo "</tbody>";
					echo "</table>";
				}else
				{
					print '<div class="alert alert-dismissible alert-danger">
                <button type="button" class="close" data-dismiss="alert">×</button>
                <strong>Sorry!</strong>Please enter correct date range.
              </div>';
				}

				}else{
					
				}

			?>

```

---

<div class="post-metadata">

**Author:** ![katsry](https://www.phphelp.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@katsry](https://www.phphelp.com/u/katsry)\
**Post date:** [July 28, 2023, 2:00pm UTC](https://www.phphelp.com/t/view-attendance-table-by-date-in-php-mysql/35543/2 "2023-07-28T14:00:37Z")

</div>

Make sure your table names and column names are correct and the database connection is properly established. Also ensure your dates are in the correct format and the logic for calculating them is correct.  
Then update this line

```auto
if(($normalized_weekday="saturday") && ($normalized_weekday="sunday"))

```

and replace it with

```auto
if($normalized_weekday=="saturday" || $normalized_weekday=="sunday")

```

You should use the logical OR `||` operator because a day cannot be both Saturday and Sunday. With the `&&` operator, both conditions have to be true which is impossible in your case.  
If this does not work well, please provide more code and information so that I can help you better. Good luck

---

<div class="post-metadata">

**Author:** ![enarco](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@enarco](https://www.phphelp.com/u/enarco)\
**Post date:** [August 23, 2023, 1:09pm UTC](https://www.phphelp.com/t/view-attendance-table-by-date-in-php-mysql/35543/3 "2023-08-23T13:09:25Z")

</div>

Thank yok this is work
