PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 12th, 2000, 11:00 PM
webnautics webnautics is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Fitzgerald Ga USA
Posts: 8 webnautics User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to webnautics
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

Reply With Quote
  #2  
Old April 13th, 2000, 08:23 AM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
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

Reply With Quote
  #3  
Old April 13th, 2000, 08:33 PM
Dist Dist is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 31 Dist User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
You could also fetch all of them to an array and use shuffle() and then pull out first 5.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Randomly Print 5 links from an Array

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap