muat Posted August 4, 2008 Share Posted August 4, 2008 I want to order the results of an SQL query by date 1st then by time. this will then alow me to insert records out of syen and for the report to still be correct. my code is currently: $sql33 = "SELECT * FROM fgqcdetails WHERE JobName = '$_GET[job]' ORDER BY CheckDate AND timeTake LIMIT $limitvalue, $limit"; this doesn't seem to be working! Quote Link to comment Share on other sites More sharing options...
Johntron Posted August 4, 2008 Share Posted August 4, 2008 The syntax is ORDER BY a,b Change the last "AND" to a comma Quote Link to comment Share on other sites More sharing options...
muat Posted August 4, 2008 Author Share Posted August 4, 2008 thay has helped, however my data is sill not in order page 1 Date 25/07 25/07 25/07 25/07 25/07 25/07 25/07 25/07 Time 10.10 10.30 10.50 11.10 11.30 11.50 9.30 9.50 page 2 Date 29/07 29/07 29/07 29/07 29/07 29/07 29/07 29/07 Time 10.00 10.20 10.40 11.00 11.20 11.40 12.00 12.20 page 3 Date 29/07 29/07 29/07 29/07 29/07 29/07 29/07 29/07 Time 7.20 7.40 8.00 8.20 8.40 9.00 9.20 9.40 $sql4 = "SELECT * FROM fgqcdetails WHERE JobName = '$_GET[job]' ORDER BY CheckDate ASC, timeTake ASC LIMIT $limitvalue, $limit"; any thoughts?? Quote Link to comment Share on other sites More sharing options...
muat Posted August 4, 2008 Author Share Posted August 4, 2008 I have sorted it. there was no problem with the sql. the data type for the 'time' fiels was a varchar therefor the system was putting them in the correct order based on the 1st number only ie 1,2,7,8,9. i channged the datat ype to a decimal (4,2) and it works perfectly. Quote Link to comment Share on other sites More sharing options...
Johntron Posted August 4, 2008 Share Posted August 4, 2008 That's probably a fairly common mistake. Quote Link to comment Share on other sites More sharing options...
revraz Posted August 5, 2008 Share Posted August 5, 2008 You could always use a real time stamp and avoid those problems. Quote Link to comment Share on other sites More sharing options...
Johntron Posted August 6, 2008 Share Posted August 6, 2008 Great advice. Timestamps are great. Use them Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.