mysqli select random
how would i select a random item using the mysqli extension? I have tried a few things but I am not getting anywhere.
how would i select a random item using the mysqli extension? I have tried a few things but I am not getting anywhere.
SELECT * FROM tablename ORDER BY RAND()
hey Craig, thx, but I did try that and it seems to be so slow with the 10k records. any chance of something a little faster/better than a simple rand?
ah yes, not so good on big recordsets.
try this(changing PK and table name as appropriate)
SELECT * FROM tblitem WHERE ItemID >= (SELECT FLOOR( MAX(ItemID) * RAND()) FROM tblitem ) ORDER BY ItemID
or
SELECT t.ItemID FROM tblitem t JOIN (SELECT(FLOOR(max(ItemID) * rand())) as maxid FROM tblitem) as tt on t.ItemID >= tt.maxid
sweet will give them a go thx very much!!
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.