Jump to content

[SOLVED] Where to put ORDER BY desc when column mixed in w date


randalusa

Recommended Posts

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.

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";

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";

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";

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.

 

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";

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.