The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
![]()
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:
$allids = $DB_site->query("SELECT id FROM " . TABLE_PREFIX . "test"); $idarray = array(); while ($ids = $DB_site->fetch_array($allids)) { $idarray[] .= $ids['id']; } $id = array_rand($idarray); |
#2
|
||||
|
||||
![]()
$allids = $DB_site->query("SELECT id FROM " . TABLE_PREFIX . "test order by RAND() LIMIT 1");
|
#3
|
|||
|
|||
![]()
Almost...if you want to get just one randomly:
[sql] SELECT column FROM table ORDER BY RAND() LIMIT 1 [/sql] 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. |
#4
|
||||
|
||||
![]()
Got it worked right the first try, thank you very much guys
![]() |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|