Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-07-2008, 04:02 AM Randomly List Items
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
Hey, guys. I have a list of ten item and I want to randomly select 5 of these items and display them. The problem is, I don't want the items to be stored in a MySQL database and I need to make sure the same item is not selected twice. Any ideas?
choskins102 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-07-2008, 04:47 AM Re: Randomly List Items
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
<?
    $list 
range(11,22);
    
$selected = array();
    
$indexes = array();

    
$iterations 0;
    while (
count($selected) < 5) {
        
$index rand(0count($list) - 1);
        if (!isset(
$indexes[$index])) {
            
$indexes[$index] = 1;
            
$selected[] = $list[$index];
        }
        
$iterations += 1;
    }

    
print_r($selected);
    
print_r($indexes);
    print 
$iterations."\n";
                   
?>
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Randomly List Items
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34694 seconds with 12 queries