display 5 random entries from mysql with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
whiteyoh
Forum Newbie
Posts: 1
Joined: Thu Jun 26, 2008 5:12 am

display 5 random entries from mysql with php

Post by whiteyoh »

Hi There,

Hope someone can help.

I need a little snippet of code that will display 5 random entries from a mysql database. I would also like a spacer between each display.

Many thanks

Paul
madan koshti
Forum Commoner
Posts: 50
Joined: Fri Jun 06, 2008 4:25 am

Re: display 5 random entries from mysql with php

Post by madan koshti »

Hi ,

This will select 5 rows randomly

select * from TABLE_NAME order by rand() limit 5


and random with spacer :

select concat(column1," ",column2," ",column3) as randomwithspace from TABLE_NAME order by rand()
Post Reply