PDA

View Full Version : Randomly pick one out of table


AnhTuanCool
09 Jan 2005, 00:08
So hi people,

I have a small question and very needed to be explained :)
I want to randomly pick an id out of a table so I wrote this


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


But it didn't work, I know my PHP and SQL skill still bad so I really need some support now. Thanks in advanced.

Creative Suite
09 Jan 2005, 00:13
$allids = $DB_site->query("SELECT id FROM " . TABLE_PREFIX . "test order by RAND() LIMIT 1");

filburt1
09 Jan 2005, 00:21
Almost...if you want to get just one randomly:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


You should pretty much never have to get the entire contents of a table. It scales like crap and you'll cripple the server after the table gets too big. The exception is when you know the table is going to have very few rows and you need to read each and every one of the rows in the table.

AnhTuanCool
09 Jan 2005, 03:13
Got it worked right the first try, thank you very much guys :)