coolphpdude Posted August 8, 2008 Share Posted August 8, 2008 Hi there, im sure this will be a quick one for most. I'm trying to order my memo's to students by date and time posted, i have the following query but for some reason my results dont seem to be output by date and time correctly. SELECT * FROM memo WHERE student='$student' ORDER BY memo_time AND memo_date DESC outputs the following... Memo ID Subject Date & Time 10 revision class 2008-08-07 20:40 11 hand in date 2008-08-08 10:31 12 review 2008-08-08 11:04 13 review 2008-08-08 11:05 14 review 2008-08-08 11:05 15 review 2008-08-08 11:05 16 review 2008-08-08 11:05 Any idea? Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/ Share on other sites More sharing options...
gabarab Posted August 8, 2008 Share Posted August 8, 2008 Why don't you save your table date and time in one single column? the layout is identical to what you need. set the column type: datetime after that, if you need only the date, from that value, you call function date() example <?php // Assuming today is: March 10th, 2001, 5:16:18 pm $getdate="2001-03-10 17:16"; $today = date("F j, Y, g:i a", $date); // March 10, 2001, 5:16 pm $today = date("m.d.y", $date); // 03.10.01 $today = date("j, n, Y", $date); // 10, 3, 2001 $today = date("Ymd", $date); // 20010310 $today = date('h-i-s, j-m-y, it is w Day z ', $date); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01 $today = date('\i\t \i\s \t\h\e jS \d\a\y.', $date); // It is the 10th day. $today = date("D M j G:i:s T Y", $date); // Sat Mar 10 15:16:08 MST 2001 $today = date('H:m:s \m \i\s\ \m\o\n\t\h', $date); // 17:03:17 m is month $today = date("H:i:s", $date); // 17:16:17 ?> you can find a more complete example on www.php.net/date Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611480 Share on other sites More sharing options...
coolphpdude Posted August 8, 2008 Author Share Posted August 8, 2008 I've got to have my first hand in for monday and got a few things to do so i might try that later. Just need to know if i've written that query correctly or is there a better way of writing it (that will give the correct result) Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611534 Share on other sites More sharing options...
alin19 Posted August 8, 2008 Share Posted August 8, 2008 i don't see a column caled memo_time or memo_date Date & Time is the only column that i see SELECT * FROM memo WHERE student='$student' ORDER BY 'Date & Time' DESC Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611537 Share on other sites More sharing options...
coolphpdude Posted August 8, 2008 Author Share Posted August 8, 2008 Sorry date & time is just the header on my table that i use to display the output, the columns are actualy called memo_date and memo_time. Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611538 Share on other sites More sharing options...
alin19 Posted August 8, 2008 Share Posted August 8, 2008 i don't understand, you have: Memo ID Subject memo_date memo_time ? Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611541 Share on other sites More sharing options...
JD* Posted August 8, 2008 Share Posted August 8, 2008 Your query should read: SELECT * FROM memo WHERE student='$student' ORDER BY memo_date DESC AND memo_time DESC Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611545 Share on other sites More sharing options...
dilum Posted August 8, 2008 Share Posted August 8, 2008 You are using , SELECT * FROM memo WHERE student='$student' ORDER BY memo_time AND memo_date DESC in here order only effect to the memo_date. Therefore i think you have to use.,, SELECT * FROM memo WHERE student='$student' ORDER BY memo_time DESC, memo_date DESC Try this! Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611546 Share on other sites More sharing options...
coolphpdude Posted August 8, 2008 Author Share Posted August 8, 2008 i'll give that a go thanks Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611547 Share on other sites More sharing options...
coolphpdude Posted August 8, 2008 Author Share Posted August 8, 2008 PERFECT!!! it brings up errors when you put AND in between, it works by seperating the two with a comma! cheers thanks for your help guys! Link to comment https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/#findComment-611548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.