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

$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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.