SELECT DISTINCT * FROM data_member left join table_checkin ON data_member.ID_Member = table_checkin.ID_Member WHERE data_member.ID LIKE '%5%' AND table_checkin.ID_Member is null
Code (PHP)
$date = '2018-08-15';
$sql = "SELECT DISTINCT * FROM data_member left join table_checkin ON data_member.ID_Member = table_checkin.ID_Member ";
$sql_day = "SELECT 'ID_Member' FROM `table_checkin` WHERE `Day` = '$date'";
$filter_day = $conn->query($sql_day);
if(isset($_GET['TEST']) && $_GET['TEST']!=""&& $_GET['text_search']=="") {
$sql .= " WHERE data_member.{$_GET['TEST']} AND NOT EXISTS (SELECT table_checkin.ID_Member FROM table_checkin WHERE Day = $date AND table_checkin.ID_Member is null)";
}
else {
}
if(isset($_GET['text_search']) && $_GET['text_search']!=""){
$sql .= " WHERE data_member.{$_GET['TEST']} LIKE '%{$_GET['text_search']}%' AND EXISTS (SELECT 'ID_Member' FROM `table_checkin` WHERE `Day` = '$date' AND table_checkin.ID_Member is null) ";
}
else{
}
$result = $conn->query($sql);
@$total=mysqli_num_rows($result);
$e_page=10; // กำหนด จำนวนรายการที่แสดงในแต่ละหน้า
$step_num=0;
if(!isset($_GET['page']) || (isset($_GET['page']) && $_GET['page']==1)){
$_GET['page']=1;
$step_num=0;
$s_page = 0;
}else{
$s_page = $_GET['page']-1;
$step_num=$_GET['page']-1;
$s_page = $s_page*$e_page;
}
$sql.=" ORDER BY ID ASC LIMIT ".$s_page.",$e_page ";
$result=$conn->query($sql);
echo $sql;
?>
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th width="150">Name</th>
<th>ID_Member</th>
<th width="130">Tel</th>
<th>Guide</th>
<th>Driver</th>
<th>Company</th>
<th>Country</th>
<th width="120">Note</th>
<th>CheckIn</th>
</tr>
</thead>
<tbody>
<tr>
<?php
if($result && $result->num_rows>0){ // คิวรี่ข้อมูลสำเร็จหรือไม่ และมีรายการข้อมูลหรือไม่
while($row = $result->fetch_assoc()) {?>
<tr>
<td ><?php echo $row['ID']; ?></td>
<td><?php echo $row['Name']; ?></td>
<td><?php echo $row['ID_Member']; ?></td>
<td><?php echo $row['Tel']; ?></td>
<td><?php echo $row['Guide']; ?></td>
<td><?php echo $row['Driver']; ?></td>
<td><?php echo $row['Company']; ?></td>
<td><?php echo $row['Country']; ?></td>
<td><?php echo $row['Note']; ?></td>
<td><a class='btn btn-sm btn-warning' href="JavaScript:if(confirm('Confirm CheckIn?') == true){window.location='insert_checkin.php? ID_Member=<?php echo $row['ID_Member']; ?>';}">CheckIn</a> </td>
<?php } }
?>
</tr>
</tbody>
</table>
</div>
</div>
<?php
page_navi($total,(isset($_GET['page']))?$_GET['page']:1,$e_page,$_GET); ?>
SELECT DISTINCT *
FROM data_member
LEFT JOIN table_checkin ON data_member.ID_Member = table_checkin.ID_Member
AND DATE_FORMAT(table_checkin.`Day`, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
WHERE table_checkin.ID_Member is null AND ...เงื่อนไขการค้นหา...