randalusa Posted October 28, 2007 Share Posted October 28, 2007 The code below... $query = "SELECT id, user, admin, ip, approve, filename, email, DATE_FORMAT(date, '%m-%e-%y@%H:%i'), orig_name, p_num FROM photo_log WHERE MONTH(date) = $month AND YEAR(date) = $year "; ... results in a table with the following headings: Upload UserName IP Address Original File Name MC File Name Uploaded App Admin. Here's where a switch is made in the code: $result = mysql_db_query($db, $query); while ($row=mysql_fetch_row($result)) { $id=$row[0]; $user=$row[1]; $admin_approved=$row[2]; $ip_add=$row[3]; $approve=$row[4]; $mc_filename=$row[5]; $email=$row[6]; $date_uploaded=$row[7]; $orig_filename=$row[8]; $photo_number=$row[9]; I dunno how to get an ORDER BY desc command in there where order by applies to $date_uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/ Share on other sites More sharing options...
pocobueno1388 Posted October 28, 2007 Share Posted October 28, 2007 Well, What column does $row[7] refer to in the database? I'm going to assume it's "date". $query = "SELECT id, user, admin, ip, approve, filename, email, DATE_FORMAT(date, '%m-%e-%y@%H:%i'), orig_name, p_num FROM photo_log WHERE MONTH(date) = $month AND YEAR(date) = '$year' ORDER BY `date` DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-379914 Share on other sites More sharing options...
randalusa Posted October 28, 2007 Author Share Posted October 28, 2007 I'll give that a try. Already attempted using: ORDER BY MONTH(date) desc Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-379922 Share on other sites More sharing options...
randalusa Posted October 28, 2007 Author Share Posted October 28, 2007 True, column 7 in the database table is 'date'. I tried ordering by date just now to no avail. The results showed up, but neither asc or desc would reverse the order. $query = "SELECT id, user, admin, ip, approve, filename, email, DATE_FORMAT(date, '%m-%e-%y@%H:%i'), orig_name, p_num FROM photo_log WHERE MONTH(date) = $month AND YEAR(date) = $year ORDER BY 'date' desc"; Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-379927 Share on other sites More sharing options...
pocobueno1388 Posted October 28, 2007 Share Posted October 28, 2007 Your putting single quotes around "date", you need to put back sticks (or whatever you call them). $query = "SELECT id, user, admin, ip, approve, filename, email, DATE_FORMAT(date, '%m-%e-%y@%H:%i'), orig_name, p_num FROM photo_log WHERE MONTH(date) = '$month' AND YEAR(date) = '$year' ORDER BY `date` DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-379930 Share on other sites More sharing options...
randalusa Posted October 28, 2007 Author Share Posted October 28, 2007 Your putting single quotes around "date", you need to put back sticks (or whatever you call them). Didn't help. Example follows: WHERE MONTH(date) = $month AND YEAR(date) = $year ORDER BY \"date\" asc"; It DID once again produce results (no syntax error noted), though no change in order by trying desc (first), then asc. Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-379933 Share on other sites More sharing options...
pocobueno1388 Posted October 28, 2007 Share Posted October 28, 2007 Your still not doing what I told you. Now you putting double quotes...I want you to put back sticks. Also, your not surrounding your variables with quotes. Please just copy and paste this and try it. $query = "SELECT id, user, admin, ip, approve, filename, email, DATE_FORMAT(date, '%m-%e-%y@%H:%i'), orig_name, p_num FROM photo_log WHERE MONTH(date) = '$month' AND YEAR(date) = '$year' ORDER BY `date` DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-379936 Share on other sites More sharing options...
randalusa Posted October 28, 2007 Author Share Posted October 28, 2007 Your still not doing what I told you. Now you putting double quotes...I want you to put back sticks. Also, your not surrounding your variables with quotes. Please just copy and paste this and try it. $query = "SELECT id, user, admin, ip, approve, filename, email, DATE_FORMAT(date, '%m-%e-%y@%H:%i'), orig_name, p_num FROM photo_log WHERE MONTH(date) = '$month' AND YEAR(date) = '$year' ORDER BY `date` DESC"; Wowwwwwww!!! I never heard of "backsticks", and figured you were merely using the wrong name for a backslash. :-( Oooops. And it worked too. Thank you soooo much. Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-379937 Share on other sites More sharing options...
GingerRobot Posted October 28, 2007 Share Posted October 28, 2007 Its backticks rather than backsticks. Quote Link to comment https://forums.phpfreaks.com/topic/75121-solved-where-to-put-order-by-desc-when-column-mixed-in-w-date/#findComment-380000 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.