Page 1 of 1
random database select
Posted: Thu Jul 05, 2007 1:15 pm
by m2babaey
Hi
I want to display random articles in my homepage from "article" table in my database
how can I do that?
thanks
Posted: Thu Jul 05, 2007 1:46 pm
by superdezign
Code: Select all
SELECT `content` FROM `table` ORDER BY RAND() LIMIT 0, 1;
Choose the Right Board
Posted: Thu Jul 05, 2007 7:10 pm
by feyd
Posted: Fri Jul 06, 2007 1:47 am
by m2babaey
superdezign wrote:Code: Select all
SELECT `content` FROM `table` ORDER BY RAND() LIMIT 0, 1;
thanks:P
what should be instead of "content"?
and what's the job for limit 0,1?
Posted: Fri Jul 06, 2007 3:29 am
by onion2k
m2babaey wrote:superdezign wrote:Code: Select all
SELECT `content` FROM `table` ORDER BY RAND() LIMIT 0, 1;
thanks:P
what should be instead of "content"?
and what's the job for limit 0,1?
You'll learn a lot more a lot faster if you learn to look for an answer in the MySQL manual first. We could tell you the specifics, but reading the manual will give you much more information.
Posted: Sat Jul 07, 2007 9:29 am
by m2babaey
Yes you are right
I was looking through net and books, but did not find something suitable in these 2 days
thanks,
Posted: Sun Jul 15, 2007 1:39 pm
by m2babaey
Now what if i want to display random "article of the day"?
The above code will output a different articles each time the homepage is loaded. but what if I want to have only 1 article displayed in a single day?
Posted: Sun Jul 15, 2007 1:48 pm
by feyd
Either come up with a randomization that uses the date to generate a unique value or use a separate table where you can associate a day with a randomly preselected record.