Pulling a Random Result

Alexej Kubarev

New member
i of the solutions would be pulling all of the articles into an indexed array and then using rand() function to generate a random index.. however this wouldnt be very optimized... you may want to get to populate an array of article_ids first.. then pick one using rand() and then query for the whole article..
Here you have yfs1.
Alexei has already explained it :p

srand ((double) microtime() * 1000000);
$random = rand(0,1);

$categories = array('Arts', 'Business', 'Computers', 'Health'); 

return $categories[$random];

hehe gesf : i mostly prefere giving suggestions to people on how to solve it and not making the whole code: that way people learn faster and that knowledge will stick with them... thats how i learned both C# and PHP
well.. thats not always a good idea ^^
i prefere coding from scratch as i can make some small adjustments on the fly. however now i have made my framework: there will be some part of the code that willb e used everywhere..
I do like coding from scratch too!
Don't worry... i just do that in some cases and mainly when i'm home... where i have everything :)