Gruzin Posted July 17, 2006 Share Posted July 17, 2006 hi guys, I hope u can help me:I've got some links in external php file and I want the sript to pick up this links in random way. please, help. Thanks Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/ Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 can you explain a bit more mate? please....when it picks them up what is it doing withit? Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59211 Share on other sites More sharing options...
Prismatic Posted July 17, 2006 Share Posted July 17, 2006 One way is to hold all the links in an array[code]<?php$LinkArr[1] = "http://www.google.com";$LinkArr[2] = "http://www.yahoo.com";$LinkArr[3] = "http://www.msn.com";$LinkArr[4] = "http://www.phpfreakes.com";?>[/code]And then use rand() to grab one of those randomly[code]<?php$LinkToShow = rand(1, count($LinkArr));?>[/code]and then show the randomly chosen link[code]<?phpecho $LinkArr[$LinkToShow];?>[/code] Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59212 Share on other sites More sharing options...
Gruzin Posted July 17, 2006 Author Share Posted July 17, 2006 thanks a lot:) Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59275 Share on other sites More sharing options...
Gruzin Posted July 17, 2006 Author Share Posted July 17, 2006 I've done it, but I need to display all the links and I want this links to be linked??? Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59280 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 so basically u want all the links in a random way that link to another website when u click on them? Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59283 Share on other sites More sharing options...
Gruzin Posted July 17, 2006 Author Share Posted July 17, 2006 yes, I want this links to be linked to the web-sites. I'am trying to make a descriptions for the links.... I mean when the link will be displayed I want some description under it Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59284 Share on other sites More sharing options...
Prismatic Posted July 17, 2006 Share Posted July 17, 2006 [code]<?php/* The array to hold the links */$LinkArr[1] = "http://www.google.com";$LinkArr[2] = "http://www.yahoo.com";$LinkArr[3] = "http://www.msn.com";$LinkArr[4] = "http://www.phpfreakes.com";/* The array to hold the descritions for the links */$LinkArrDesc[1] = "This is a descrition for google!";$LinkArrDesc[2] = "This is a descrition for Yahoo!";$LinkArrDesc[3] = "This is a descrition for MSN!";$LinkArrDesc[4] = "This is a descrition for PHPFreaks!";/* Grab a link randomly */$LinkToShow = rand(1, count($LinkArr));/* Now show the link as a clickable link and the descritpion under it */echo "<a href='". $LinkArr[$LinkToShow] ."'>". $LinkArr[$LinkToShow] ."</a><br>". $LinkArrDesc[$LinkToShow];?>[/code] Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59287 Share on other sites More sharing options...
Gruzin Posted July 17, 2006 Author Share Posted July 17, 2006 Thanks a lot you realy helped me:) can I make all this links to be displayed? Thanks Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59289 Share on other sites More sharing options...
Prismatic Posted July 17, 2006 Share Posted July 17, 2006 To show all links use this:[code]<?phpfor($i=1; $i <= count($LinkArr); $i++){ echo "<a href='". $LinkArr[$i] ."'>". $LinkArr[$i] ."</a><br>•". $LinkArrDesc[$i] ."<br><br>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59290 Share on other sites More sharing options...
Gruzin Posted July 17, 2006 Author Share Posted July 17, 2006 Thank you very much!!! You are so Kind:) Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59291 Share on other sites More sharing options...
Prismatic Posted July 17, 2006 Share Posted July 17, 2006 No problem :) Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59292 Share on other sites More sharing options...
Gruzin Posted July 17, 2006 Author Share Posted July 17, 2006 And one more thing please:) Can we display only first 20 links in random way? Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59296 Share on other sites More sharing options...
Prismatic Posted July 17, 2006 Share Posted July 17, 2006 Yep. This code will show the first 20 randomly, or all of them in random order if the ammount of links is under or equal to 20.[code]<?phpif(count($LinkArr) > 20) $Max = 20;else $Max = count($LinkArr);for($i=1; $i <= $Max; $i++){ $LinkToShow = rand(1, count($LinkArr)); echo "<a href='". $LinkArr[$LinkToShow] ."'>". $LinkArr[$LinkToShow] ."</a><br>•". $LinkArrDesc[$LinkToShow] ."<br><br>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59305 Share on other sites More sharing options...
Gruzin Posted July 17, 2006 Author Share Posted July 17, 2006 Thanks man, you are great:) Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59311 Share on other sites More sharing options...
Prismatic Posted July 17, 2006 Share Posted July 17, 2006 Yep, no problem :) Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59313 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 Please also add the code that let's users get the random link from a database ok cheers mate.exampleexplode("",$links);foreach($links AS $LinkArr);/* The array to hold the links */$LinkArr[1] = "http://www.google.com";$LinkArr[2] = "http://www.yahoo.com";$LinkArr[3] = "http://www.msn.com";$LinkArr[4] = "http://www.phpfreakes.com";somthink like that if the links are in the database This code needs to be corrected theo cheers. Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59330 Share on other sites More sharing options...
Gruzin Posted July 18, 2006 Author Share Posted July 18, 2006 Thanks guys I've done it with your help, but I've got a little problem: http://www.3d.caucasus.net here is my draft site, on the left u can see this linkbox (random links), so there is a problem for me on the first line of this link box, link is shown 2 times and not seperated.... what can I do to make this first line look like below ones? Link to comment https://forums.phpfreaks.com/topic/14820-need-some-random-help/#findComment-59833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.