Jump to content

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
https://forums.phpfreaks.com/topic/202187-order-by-record-within-month/
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";

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

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.