#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Fitzgerald Ga USA
    Posts
    8
    Rep Power
    0
    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!

    Regards,
    Brant
    Webnautics
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    16
    try

    > 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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    You could also fetch all of them to an array and use shuffle() and then pull out first 5.

Similar Threads

  1. permissions after uploading
    By Paul Niessen in forum Perl Programming
    Replies: 3
    Last Post: February 15th, 2004, 05:51 PM
  2. Help with HTML Parsing
    By musashiBRS in forum Python Programming
    Replies: 6
    Last Post: February 13th, 2004, 02:32 AM
  3. Writing to two *.csv files
    By CAR in forum Perl Programming
    Replies: 4
    Last Post: February 7th, 2004, 04:39 PM
  4. need help with testing non-alphanumeric input
    By pinkipodmini in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 01:48 PM
  5. howto get NICK_NAME and print results?
    By marnixvandalen in forum Perl Programming
    Replies: 0
    Last Post: January 5th, 2004, 01:35 AM

IMN logo majestic logo threadwatch logo seochat tools logo