Jump to content


Photo

Need some random help


  • Please log in to reply
17 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 09:08 AM

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
I don't need your script, I'll try to write it myself

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 09:09 AM

can you explain a bit more mate? please....

when it picks them up what is it doing withit?

#3 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 July 2006 - 09:21 AM

One way is to hold all the links in an array
<?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";
?>

And then use rand() to grab one of those randomly
<?php
$LinkToShow = rand(1, count($LinkArr));
?>

and then show the randomly chosen link
<?php
echo $LinkArr[$LinkToShow];
?>


#4 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 12:07 PM

thanks a lot:)
I don't need your script, I'll try to write it myself

#5 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 12:34 PM

I've done it, but I need to display all the links and I want this links to be linked???
I don't need your script, I'll try to write it myself

#6 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 12:38 PM

so basically u want all the links in a random way that link to another website when u click on them?

#7 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 12:40 PM

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
I don't need your script, I'll try to write it myself

#8 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 July 2006 - 12:48 PM

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

?>


#9 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 12:51 PM

Thanks a lot you realy helped me:) can I make all this links to be displayed? Thanks
I don't need your script, I'll try to write it myself

#10 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 July 2006 - 12:54 PM

To show all links use this:

<?php
for($i=1; $i <= count($LinkArr); $i++){
	echo "<a href='". $LinkArr[$i] ."'>". $LinkArr[$i] ."</a><br>•". $LinkArrDesc[$i] ."<br><br>";
}
?>


#11 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 12:56 PM

Thank you very much!!! You are so Kind:)
I don't need your script, I'll try to write it myself

#12 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 July 2006 - 12:57 PM

No problem :)

#13 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 01:06 PM

And one more thing please:) Can we display only first 20 links in random way?
I don't need your script, I'll try to write it myself

#14 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 July 2006 - 01:16 PM

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.
<?php
if(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>";
}
?>


#15 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 17 July 2006 - 01:20 PM

Thanks man, you are great:)
I don't need your script, I'll try to write it myself

#16 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 July 2006 - 01:22 PM

Yep, no problem :)

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 01:32 PM

Please also add the code that let's users get the random link from a database ok cheers mate.

example


explode("",$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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 18 July 2006 - 08:25 AM

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?
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users