我想要实现的是按日期和时间排序(首先是pm,然后是pm)。当我用这段代码尝试它时(ORDER BY reservationdate DESC,reservationtime ASC),这就是我得到的。 按时间排序am和pm
我对日期没有问题,但时间没有正确排序。我想要的是先用“am”表示所有的时间,然后用“pm”跟着时间。
这里是如何得到的日期和时间,并将其插入到数据库
$reservationDate = date("F j, Y");
$reservationTime = date(g:i a");
$insertdata = "INSERT INTO reservations (reservationdate, reservationtime)VALUES('$reservationDate', '$reservationTime')";
这是代码中显示它
<?php
$query = "SELECT * FROM reservations ORDER BY reservationdate DESC, reservationtime ASC LIMIT " . $this_page_first_result . ',' . $results_per_page;
$search_result = filterTable($query);
?>
</div>
<!DOCTYPE html>
<html>
<head>
<title>Admin Control</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<form action="adminControl.php" method="GET">
<input id="searchBox" type="text" name="valueToSearch" placeholder="type information here">
<input id="searchButton" type="submit" name="search" value="Search">
<div style="overflow-x:auto;">
<table class="reservations-table">
<tr>
<th class="thFirstName">First Name</th>
<th class="thLastName">Last Name</th>
<th class="thEmailAddress">Email Address</th>
<th class="thContactNumber">Contact Number</th>
<th class="thSpeaker">Speaker</th>
<th class="thTopic">Topic</th>
<th class="thLocation">Location</th>
<th class="thAudience">Audience</th>
<th class="thCount">Count</th>
<th class="thTime">Time</th>
<th class="thDate">Date</th>
<th class="thAction">Reservation Date</th>
<th class="thAction">Reservation Time</th>
<th class="thAction">Status</th>
<th class="thAction">Action</th>
<th class="thAction">Action</th>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['lastname'];?></td>
<td><?php echo $row['emailaddress'];?></td>
<td><?php echo $row['contactnumber'];?></td>
<td><?php echo $row['speaker'];?></td>
<td><?php echo $row['topic'];?></td>
<td><?php echo $row['location'];?></td>
<td><?php echo $row['audience'];?></td>
<td><?php echo $row['count'];?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['date'];?></td>
<td><?php echo $row['reservationdate']?></td>
<td><?php echo $row['reservationtime']?></td>
<td><?php echo $row['reservationstatus'];?></td>
<td><?php echo "<a style='padding:6px; float:left; background-color:#45a049; color:white; border-radius: 3px;' href='adminControl.php?epr=approve&speakerName=".$row['speaker']."&reservationStatus=".$row['reservationstatus']."&reservationId=".$row['id']."'>approve </a>";?></td>
<td><?php echo "<a style='padding:6px; float:left; background-color:red; color:white; border-radius: 3px;' href='adminControl.php?epr=delete&reservationId=".$row['id']."'>delete</a>";?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</div>
</body>
</html>
使用重复主题将日期和时间字符串转换为单个日期时间表达式,然后按该表达式进行排序。 – Shadow