April 13th, 2000, 12:00 AM
Okay....situation is this:
I'm running an auction that has featured auctions, and as most other auction sites, I want to rotate 5 - 10 Featured on the front page. I can easily get an array of ALL featured auctions from the MySQL database. The question is this:
How do you write PHP code to choose only 5 of them, and not choose the same one twice? I'm using PHP3. I only have 8 featured auctions in my database right now, and the way I see it, if I can make this thing work with only 8, when I get 200+ featured in the database, it will work just as well.
I have searched for HOURS for random PHP scripts, but they only choose ONE random number, which is really easy...I need 5 different ones, with out duplicates.
Any help would be wonderful!
April 13th, 2000, 09:23 AM
> select auction_name, auction_name*0 +rand() as rand_col
> order by rand_col
> limit 5;
This is a way to fool the optimizer in MySQL 3.22.2x and make a pseudo column to randomize output
April 13th, 2000, 09:33 PM
You could also fetch all of them to an array and use shuffle() and then pull out first 5.