I would like to have user can see their today picture uploaded on profile page.
Is this correct?
SELECT * FROM pictures
WHERE userid = '$userid'
ORDER BY pictureuploaddate < DATE_ADD(NOW(), INTERVAL 1 DAY);
Still not working. Thanks for the help.
You would get something like:
SELECT *
FROM pictures
WHERE userid = '$userid' AND
DATE(pictureuploaddate) = CURDATE() # Match date without time
ORDER BY pictureuploaddate DESC
Why do you ORDER BY and use an = in it? It should be todays date, just add it to the WHERE. If you want to get the latest picture first you can ORDER BY pictureuploaddate DESC
Also it's better to compare dates instead of smaller than if you want current date. Because it is faster to match.
I know you picked an answer already, but to avoid any confusion with multiple uploads on the same day, you could have also done:
SELECT *
FROM pictures
WHERE userid = '$userid'
ORDER BY pictureuploaddate DESC
LIMIT 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With