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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.