2017-08-13 10 views
0

私が達成したいのは、日時(最初は午後、午後は午後)で表を注文することです。私はこのコード(ORDER BY reservationdate DESC、reservationtime ASC)で試してみると、これは私が持っているものです。 enter image description here時間順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> 
+0

重複するトピックを使用して日付と時刻の文字列を1つのdatetime式に変換し、その式で並べ替えます。 – Shadow

答えて

1

おそらく、reservationtimeとして格納されて表示する際にコードです文字列は、時間ではありません。適切な保管方法を使用する必要があります。

あなたは簡単にstr_to_date()を使用して、時間にキャストすることができます。これは、アカウントにAM/PMがかかります

order by str_to_date(reservationtime, '%l:%i %p') 

+0

。あなたはどこでこのことを学びましたか?私はこれが学校で教えられたものであり、いくつかの不慣れなレッスンではないと思います。あなたの親切な先生に感謝。 – Red

+1

@Red。 。 。老人の経験にちょうどそれをチョーク。 –

関連する問題