I query my database by date and order it by time. The issue is that the times are stored as strings not integers in the database. So they do not come out in the correct order. I am trying to use a PHP array to order them correctly, but it is giving me errors. I found this script online and others have said it worked for them. It is not working for me, maybe someone can tell me what I’m doing wrong. Here is the script:
[code=php]
$array = array (‘9:00 AM’, ’10:00 AM’, ’10:30 AM’, ’11:00 AM’, ’11:30 AM’, ’12:00 PM’, ’12:30 PM’, ‘1:00 PM’, ‘1:30 PM’, ‘2:00 PM’, ‘2:30 PM’, ‘3:00 PM’);
$list = implode(‘,’, $array);
$orderbylist = ‘ORDER BY ‘; // initialize
foreach ($array as $time) {
$orderbylist .= “time=$time ASC,”;
}
$orderbylist = rtrim($orderbylist, ‘, ‘);
$query = “SELECT CONCAT( last_name, ‘, ‘, first_name) AS name, date AS date, time AS t, phone_number AS pn, email AS e, comments AS c, user_id AS id FROM client_info WHERE (date = ‘$d’) AND time IN ($list) $orderbylist”;