Jump to content

[SOLVED] random link list?


samoht

Recommended Posts

i dont know if its the MOST efficient way, but heres an idea, set a variable = rand($min,$max) and then set each number == to a a value between min and max, FOR example:

 

$rand=Rand(1,4)

 

if($rand == 1)

{

echo"the link";

}

elseif($rand==2)

{

echo"link 2";

}

 

and so on, it provides randomness, and hard coded links =D

Link to comment
Share on other sites

$list = array("<a href='something'><img></a>", "<a href='something2'><img></a>");
for ($i=0;$i<rand(1, count($list));$i++)
  $link = $list[$i];

 

If the list is an array, you can do it like that. You can do the same thing if the list is in a file.

 

EDIT: Actually, if it is in an array, you can just use array_rand(). http://us2.php.net/manual/en/function.array-rand.php

Link to comment
Share on other sites

thanks for the help,

 

I tried:

<?php 
	$list = array('<a href="http://www.link1.com" target="_blank"><img src="assets/logo1.jpg" /></a><br>','<a href="http://link2.org" target="_blank"><img src="assets/logo2.jpg" /></a>','<a href="http://www.link3.org" target="_blank"><img src="assets/logo3.jpg" /></a>');
	$rand_link = array_rand($list,3);
	echo $list[$rand_link[0]]. "\n";
	echo $list[$rand_link[1]]. "\n";
	echo $list[$rand_link[2]]. "\n";?>

Which seems to work fine - and was quite easy!

 

Thanks again

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.