Jump to content

Recommended Posts

Can somebody help me change this line of code:

photos WHERE approved=1 AND cat IN (501,511,502,503,562,504,506,505,508,2,510) ORDER BY date DESC LIMIT 10", $link);

So that instead of grabbing the 10 latest items of content from my site, it instead grabs 10 random items from only the most recent week?

 

I am a real noob when it comes to php and I'm thinking this can be changed using the rand() command, but I have no idea how to make it so that it only chooses those random items from the past week.

 

Thanks for any help you can provide on this probably simple change.

Link to comment
https://forums.phpfreaks.com/topic/282870-getting-weekly-random-instead-of-latest/
Share on other sites

try

SELECT * FROM
    (
    SELECT whatever 
    FROM photos
    WHERE approved=1 
    AND cat IN (501,511,502,503,562,504,506,505,508,2,510)
    AND date BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE()
    ) as thisweek
ORDER BY RAND()
LIMIT 10;
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.