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
display multiple random links
Old 09-15-2008, 04:51 PM display multiple random links
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Hi

I have been trying to impliment 3 different things on my site at the same time which is causing problems as I have not been focussed on any one of them .
I have prioritised the work and have decided what I want to do 1st and would appreciate a little direction on how to get me started (this is the one I have done most reading on unfortunatley)

I have a list of links and want to narrow the list displayed. More specifically I want to show a random selection of links each time the page is loaded. So if I have 20 links (to my own articles) I would like to display something like any 6 of the 20 at one time.

Could someone direct me to a tutorial that could show me how to do this (I would rather use php so the links are selected prior to page load). I have read a little about arrays which may be the answer (I dont have a database or CMS).

Thanks in advance.
__________________

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
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
 
Register now for full access!
Old 09-21-2008, 11:25 AM Re: display multiple random links
TyR
TyR's Avatar
Super Talker

Posts: 139
Location: Frei - Norway
Trades: 0
I hope I didn't misunderstand your question, but I wrote up something quick. It might not be so easy to understand, but I guess it's worth a try
PHP Code:
<?php                           
// Each link will be stored in an array.
// $links is an array of all the link arrays.
$links = array(
        array(
'url'=>'http://www.google.com''label'=>'Google'),
        array(
'url'=>'http://www.digg.com''label'=>'Digg'),
        array(
'url'=>'http://www.yahoo.com''label'=>'Yahoo!'),
        array(
'url'=>'http://www.ask.com''label'=>'Ask'),
        array(
'url'=>'http://www.reddit.com''label'=>'Reddit')
    );
                     

// This will pick out 3 keys from the $links array. A key is the position of a link array.
$random_keys array_rand($links3);

// Here we go through each of the keys, and print out the values from the $links array                                                           
foreach ($random_keys as $key) {
    
printf("<a href=\"%s\">%s</a><br />"$links[$key]['url'], $links[$key]['label']);
}
?>
That script will print out 3 random links from the $links array.


if you want to find out what the functions I used actually do, you should look it up at php.net
like: www.php.net/array_rand

That's how I learned PHP. By tinkering with other peoples code and learning how all the functions they used works.

Hope it helps
__________________

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

Last edited by TyR; 09-21-2008 at 01:03 PM.. Reason: made some mistakes
TyR is offline
Reply With Quote
View Public Profile
 
Old 09-23-2008, 10:03 PM Re: display multiple random links
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Thanks TyR
__________________

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

Last edited by bakerc; 09-23-2008 at 10:13 PM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Reply     « Reply to display multiple random links
 

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.24038 seconds with 12 queries