grk101 Posted April 16, 2008 Share Posted April 16, 2008 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";?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 16, 2008 Share Posted April 16, 2008 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>"; } } ?> Quote Link to comment Share on other sites More sharing options...
grk101 Posted April 16, 2008 Author Share Posted April 16, 2008 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>"); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 16, 2008 Share Posted April 16, 2008 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>"; } } ?> Quote Link to comment Share on other sites More sharing options...
grk101 Posted April 16, 2008 Author Share Posted April 16, 2008 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 Quote Link to comment Share on other sites More sharing options...
grk101 Posted April 16, 2008 Author Share Posted April 16, 2008 any idea? Quote Link to comment Share on other sites More sharing options...
tinker Posted April 16, 2008 Share Posted April 16, 2008 I based mine on http://www.rawstar7.co.uk/site/pro/php/general/tut_rand_nums.html... Quote Link to comment Share on other sites More sharing options...
grk101 Posted April 16, 2008 Author Share Posted April 16, 2008 we got the idea above, which works fine.. but it shows the URL - i wanted help so it shows just the NAME cwhich is clickable that is why i reference the <a> tag Quote Link to comment Share on other sites More sharing options...
grk101 Posted April 17, 2008 Author Share Posted April 17, 2008 bump anyone Quote Link to comment Share on other sites More sharing options...
laffin Posted April 17, 2008 Share Posted April 17, 2008 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] Quote Link to comment Share on other sites More sharing options...
grk101 Posted April 17, 2008 Author Share Posted April 17, 2008 hhmm not sure, the " redarrow " method works fine and good. but instead of the URL showing how do we get the names-- Quote Link to comment Share on other sites More sharing options...
grk101 Posted April 19, 2008 Author Share Posted April 19, 2008 bumpie? 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.