luke777 Posted April 29, 2007 Share Posted April 29, 2007 I need some kind of code in php that can display 10 random links from a big list of links. So i have a file links.php which contains a list of lets say 1000's of links, how can i grab just 10 RANDOM links from that list to display on a webpage. Please help me ! Thanks Luke. Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 29, 2007 Share Posted April 29, 2007 Would have been a nice idea to have had the links in a database. Then this would have been trivial. Does links.php contain anything except thousands of lines each one of which is a link? What's its structure? Post a few lines of it. Quote Link to comment Share on other sites More sharing options...
php_joe Posted April 29, 2007 Share Posted April 29, 2007 Try this: <? $lines = file("./link_list.txt"); shuffle($lines); $i = '0'; while($i < 10){ echo "<a href=\"$lines[$i]\">$lines[$i]</a>"; $i++; } ?> Quote Link to comment Share on other sites More sharing options...
luke777 Posted April 29, 2007 Author Share Posted April 29, 2007 Ok I got this working But the only probelm is it sometimes displays the same link twice :S Is there some way of removing duplicates??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 29, 2007 Share Posted April 29, 2007 Oh, you mean your original list has duplicates? Quote Link to comment Share on other sites More sharing options...
bobleny Posted April 29, 2007 Share Posted April 29, 2007 Dang while loops! I think you should use this instead... They do the exact same thing though.. lol <?php $lines = file("./link_list.txt"); shuffle($lines); for($i = 0; $i < 10; $i++) { echo "<a href=\"$lines[$i]\">$lines[$i]</a>"; } ?> Also, I believe the only way to get duplicates, is if you have duplicates in the file.... Quote Link to comment Share on other sites More sharing options...
luke777 Posted April 30, 2007 Author Share Posted April 30, 2007 Ok thanks alot for your help, great forum ill be sticking around ! Luke. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.