Current location: Hot Scripts Forums » Programming Languages » PHP » random link problem


random link problem

Reply
  #11 (permalink)  
Old 06-11-03, 03:12 PM
doogi doogi is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
hmm everything what is more complicated then html is a difficult for me
if my idea isn't possible in php my second idea is to make pics1.txt, pics2.txt and pics3.txt and divide all pictures
but that way pictures from pics3.txt will never exist in a line one

btw i hava also exact same problem with llinks with descriptions which are among pictures


doogi
Reply With Quote
  #12 (permalink)  
Old 06-11-03, 05:07 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetingz...

I've gotten the following code to work...

Basically put it into showads.php and include('showads.php') where you need the pics to show.

PHP Code:

<?php


  
// Check if already assigned
  
if (!isset($DoneImages))
  {
    
$DoneImages = array();
  }

  
$ile  5;
  
$file file("pics.txt");

  echo 
'<table width="600"><tr>';
  echo 
"\n";

  
srand((double)microtime()*1000000);

  for(
$i=0$i<$ile$i++)
  {
    
// Pic Random Numbers that arn't in $DoneImages
    
do
    {
      
$Pic Rand(0Count($file) - 1);  // Had to add -1 so that there would always be $ile per row...
    
}while (in_array($Pic$DoneImages));
    
    
// Add currently selected random pic to $DoneImage
    
$DoneImages[] = $Pic;

    
$sp explode('||'$file[$Pic]);
    if(
$sp[0] != '')
    {
      echo 
'<td align=middle>';
      echo 
"\n";

      echo 
'<a href="'.$sp[2].'"><img src="'.$sp[0].'" border=3></a><br>';
      echo 
"\n";

      echo 
'<font style="font-weight: bold; font-size: 11px; font-family: Tahoma">'.$sp[1].'<br></font>';
      echo 
"\n";

      echo 
'</td>';
      echo 
"\n";
    }
  }

  echo 
'</tr></table>';
  echo 
"\n";
?>
Hope this help....
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
  #13 (permalink)  
Old 06-12-03, 04:22 AM
The Wolf's Avatar
The Wolf The Wolf is offline
CMS Developer
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
I have some nicer code...

It randomly loads from the file, but only takes one entry once.

This is the file it reads from:
Code:
http://www.corephp.org|/links/corephp_01.png|Core PHP.org
http://www.yoursite.net|/links/corephp_02.png|Core PHP.org
http://www.yoursite.com|/links/corephp_03.png|Core PHP.org
http://www.yoursite.net|/links/corephp_04.png|Core PHP.org
http://www.yoursite.com|/links/corephp_05.png|Core PHP.org
http://www.yoursite.net|/links/corephp_06.png|Core PHP.org
and this is the code:
Code:
<?php

# Read the text file and split it into lines:
$file = file_get_contents("./links.txt");
$line = split("\n", $file);

# Init some vars:
$keys = array();

# Make a random list of numbers with
# no duplicates and display the info
# from the text file:
while (count($keys) <= 1) {
	$rand = rand(0, count($line) - 1);
	if (!in_array($rand, $keys)) {
		# Add the key to the $key var:
		$keys[] = $rand;
		
		# Split the text, then display it:
		$text = split("\|", $line[$rand]);
		print "<a href=\"$text[0]\"><img alt=\"$text[2]\" src=\"$text[1]\" border=\"0\"></a><br />";
	}
}

?>
Good luck, hope mine works for you.
Reply With Quote
  #14 (permalink)  
Old 06-12-03, 04:55 PM
doogi doogi is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
thx guys for your big help

The Wolf-somehow it doesn;t work for me. It can be a problem with me because almost everyhing what i can do with php is copy paste but thx again


ChristGuy - thank you very much it's probably i've been looking for
, anyway it works , nothing doubled .
could you do same think with my links.txt?
PHP Code:

<?

//start of the script
$ile 25;
$file file("links.txt");
for(
$i=0;$i<$ile;$i++)
{
    
srand((double)microtime()*1000000);
    
$link $file[array_rand($file)];
    
$sp explode("||"$link);
    if(
$sp[0]<>"")
    {
        echo 
"".$sp[0]." <a href=\"".$sp[1]."\">".$sp[2]."</a><br>";
    }
}
//end of the script
?>
btw.
i use notpad to write txt file but too much infos fot it.
can i use wordpad to create txt.
does lenght of txt file wit all links make a visible difference in loading of the page?

thx
doogi
Reply With Quote
  #15 (permalink)  
Old 06-13-03, 01:59 AM
The Wolf's Avatar
The Wolf The Wolf is offline
CMS Developer
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Damn, ok. at least you got it working, the length of the txt file would make a small diff, but only very small...
Reply With Quote
  #16 (permalink)  
Old 06-13-03, 05:10 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetinz...

try the following..
PHP Code:

<?

  
if (!isset($DoneImages))
  {
    
$DoneImages = array();
  }

  
//start of the script
  
$ile 25;
  
$file file("links.txt");

  for(
$i=0;$i<$ile;$i++)
  {
    
srand((double)microtime()*1000000);

    do
    {
      
$Pic rand(0Count($file) - 1);
    } while (
in_array($Pic$DoneImages));

    
$DoneImage[] = $Pics;

    
$sp explode("||"$file[$Pic]);

    if(
$sp[0]<>"")
    {
      echo 
"".$sp[0]." <a href=\"".$sp[1]."\">".$sp[2]."</a><br>";
    }
  }
  
//end of the script
?>
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
  #17 (permalink)  
Old 06-15-03, 03:29 AM
doogi doogi is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
it works
thank you very much again

best regards
doogi
Reply With Quote
  #18 (permalink)  
Old 06-15-03, 06:43 AM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Glad it worked....

About editing text files... you can use Wordpad... Just save as text..

BTW.. I use EditPad Lite http://www.editpadlite.com/

Kinda like notepad on steroids....
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
  #19 (permalink)  
Old 03-04-09, 01:00 AM
JohnnyDoomo JohnnyDoomo is offline
New Member
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

I found this thread through Google. Can somebody please help me change this code so that it works with text links? Similar to the thread owner, I do not want any link to be duplicated.

I do not really know any php or how the links and their clickable text should be organized in the text file.

Can somebody please help me edit this code so that it will work for a list of 25 or so random links?

I would appreciate any help coders can provide. Thanks!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Different type of link counter mdhall Script Requests 2 10-10-03 01:19 PM
Make a query that makes a field a link to the entire row mdhall PHP 8 10-09-03 06:18 PM
file download problem ukyankee Perl 6 10-04-03 10:39 PM
session problem afkaar PHP 0 08-27-03 04:43 AM


All times are GMT -5. The time now is 06:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.