Jump to content

Help - Random Link Rotator? changer..


grk101

Recommended Posts

Hello -  I have a DIV tag, that links

 

Five recipes like this..    but the name 1 reciple is actually the link..

 

1 Recipe

1 Recipe

1 Recipe

1 Recipe

1 Recipe

 

-- what i am trying to do is , put more recipes, but always change the five..

 

I found one script on this site that someone used But i dont know how to apply for me

 

Some Help would really be appreciated -

 

please and thank you  ???

<?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";?>

Link to comment
Share on other sites

Try it this way mate....

 

<?php

$l=array("http://www.html.com","http://www.msn.co.uk","http://www.fool.com",
"http://www.google.co.uk","http://www.yahoo.com");

shuffle($l);

for($i=1; $i<count($l); $i++){

if(PREG_MATCH("/^(http)(\:\/\/(w){3}\.)[a-zA-Z](.?)[a-zA-Z]{2,3}/",$l[$i])){


echo "link $i <a href='$l[$i]'>$l[$i]</a><br><br>";

}
}

?>

Link to comment
Share on other sites

is there a way to make it

 

 

so that    LINK 1 is actually the link?

 

not like Link : www.blah.com

 

?

 

but always to display 5 results?

 

i also found this link

 

which is what i am talking about but i can't make it link seperate ones

 

<?
// array with link entries in the form url|description
$linkarray = array("http://php.net/|PHP Official Site and Distribution",
"http://www.devshed.com/|DevShed - Open Source Resources",
"http://www.e-gineer.com/phpkb/index.phtml|e-gineer - PHP Knowledge Base",
"http://phpclasses.upperdesign.com/|PHP Classes Repository",
"http://www.phpbuilder.com/|PHPBuilder.com - PHP Resources",
"http://phtml.com/|phtml.com - Free PHP Scripts",
"http://www.phpwizard.net/|phpWizard.net - PHP Resources",
"http://px.sklar.com/|PX: PHP Code Exchange",
"http://www.weberdev.com/|Berber's Web Development Pages"); 

// seed the random number generator
srand((double)microtime()*1000000);
// get a random entry
$randval = rand(0,count($linkarray)-1); 

// explode random entry into an array
$entry = explode("|",$linkarray[$randval]);
// print entry
print ("Visit: <a href=\"$entry[0]\" target=\"_blank\">$entry[1]</a>");

?>

Link to comment
Share on other sites

it dosent make sence for the user to see the link number mixed up.......

 

so what you trying to acheve

 

if you wanted to controll the url to do somethink you use the $_GET['fuction']

and use the url with the value..........

 

example

 

url

<?php
http://www.html.com?cmd=me 
?>

 

$_GET function for that url

<?php
if($_GET['cmd']=="me"){
// do somethink with the cmd==me from url
}
?>

 

 

<?php

$l=array("http://www.html.com","http://www.msn.co.uk","http://www.fool.com",
"http://www.google.co.uk","http://www.yahoo.com");

shuffle($l);

for($i=1; $i<count($l); $i++){

if(PREG_MATCH("/^(http)(\:\/\/(w){3}\.)[a-zA-Z](.?)[a-zA-Z]{2,3}/",$l[$i])){


echo "link $i <a href='$l[$i]'>$l[$i]</a><br><br>";

}
}

?>

 

Link to comment
Share on other sites

hi, sorry i think i am confusing myself here lol

 

 

 

I dont want the USER to see the URL u know?

 

I just want them to see

 

Italian Salad -- and when they click on it, it goes to the recipe

 

<a href="www.italian.com">Italian Salad</a>

 

basically thats all

 

like 20 links that change when ever the page loads

 

Link to comment
Share on other sites

question is HOW do u keep from getting duplicates?

 

$dupe_araay=$listarray;
$rand_keys=array();
srand((double)microtime()*1000000);
for($i=0;$i<5;$i++)
{
   $avail_keys=array_keys($dupearray);
   $randval = rand(0,count($linkarray)-1);
   $rand_keys[]=$avail_keys[$randval];
   unset($dupearray[$avail_keys[$randval]]);
}
unset($dupearray);
[code]

here we make a copy of the list, and we grab 5 random keys, removing the key from the list. so u are assured no dupes are in the list.

than just proceed to display the list with a foreach loop 

[/code]

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.