Jump to content

Order by record within month?


brmcdani

Recommended Posts

I am trying to create a mysql statment where the following records are pulled out based on which month it is.  The following statment I have will pull out the latest photos and order them by the date.  However I want it to pull out records only from the current month.

 

Any ideas will be appreciated.  Thanks

 

$sql="select * from members,photos where members.username=photos.username and approved='Y'  and active=1 order by photos.upldate";

Link to comment
Share on other sites

$sql="
  SELECT * 
  FROM 
    members AS m
  INNER JOIN
    photos AS p
  ON 
    m.username=p.username
  WHERE
    approved='Y'  
    AND active=1
    AND MONTH(p.upldate) = MONTH(CURDATE()) 
  ORDER BY
    p.upldate DESC";

Link to comment
Share on other sites

Thanks I got figured it out as soon as you posted.  Here was my solution:

 

$sql="select * from members,photos WHERE members.username=photos.username and YEAR(upldate) = YEAR(CURDATE()) AND MONTH(upldate) = MONTH(CURDATE()) and approved='Y'  and active=1 order by photos.upldate";

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.