Page 1 of 1

display 5 random entries from mysql with php

Posted: Thu Jun 26, 2008 5:16 am
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

Re: display 5 random entries from mysql with php

Posted: Thu Jun 26, 2008 6:59 am
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()