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