Jump to content

LIMIT and RAND()


mcmuney

Recommended Posts

Oops, forgot something. I also need to order it by something, so my code would look like this:

[code]

$result = mysql_query("SELECT * FROM table ORDER BY x LIMIT 0,5")
or die(mysql_error());
[/code]

I would then want to apply a rand() display, which will display 1 random from the 5 results.
Link to comment
https://forums.phpfreaks.com/topic/19837-limit-and-rand/#findComment-86803
Share on other sites

I used the following recently on a site, which allowed me to choose the most recent items and display them randomly:

[code]SELECT tblName.item FROM tblName WHERE MONTH(itemDate) = MONTH(CURDATE()) AND YEAR(itemDate) = YEAR(CURDATE()) ORDER BY RAND()  LIMIT 0, 5[/code]

I used WHERE instead of ORDER to select the items I wanted.

HTH.

Joss
Link to comment
https://forums.phpfreaks.com/topic/19837-limit-and-rand/#findComment-87266
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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