Link to home
Start Free TrialLog in
Avatar of doyle007
doyle007

asked on

Build dynamic links

Hey guys,
I'm trying to do something I can normally do in C language, but in PHP and having some issues. Might be my C way of thinking!

Basically, I'm scanning a directory for filenames, and then I want to dynmiacially build a html link with that filename in it...But, I need to save the value as $_SESSION[] info so I can use it in the next page that the link refers too...if that makes sense...

		$handle ="";
		$count=0;
		if ($handle = opendir('../videos')) 
		{
		    while (false !== ($file = readdir($handle))) 
			{
				if (($file == ".") || ($file == "..")) { continue; };
		        
				if (stripos($file, "flv"))
				{
                                        //in C i can append an integer (with some work) to the end of a variable name. So each iteration of the loop the variable will be called $link1, $link2, $link3 and so on. 

					$link.$count = $file;
					$count++;
				}
					
				}

		    }
		    closedir($handle);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doyle007
doyle007

ASKER

Kshna - Your method works. In the meantime however I did workout how to do it...

		
			<?php
			//Scan the Directory for videos and save them
			$handle ="";
			$link[]="";
			$count=0;
			
		if ($handle = opendir('videos')) 
		{
		    while (false !== ($file = readdir($handle))) 
			{
				if (($file == ".") || ($file == "..")) 
				{ 
					continue; 
				};
				
				if (stripos($file, "flv"))
				{
					$link[$count] = $file;
					$count++;
				}
		    }
		    closedir($handle);

//Display the links of the videos to CLICK
			$count2=0;
			echo "<h1>The following videos are available to you...</h1>";
			while ($count2 <= $count)
			{	
				echo "<br>";
				echo  "<a href=\"http:/blah.com/index.php?video=$link[$count2]\">".$link[$count2]."</a>";	
				echo "<br>";
				$count2++;	
			}
		}

			?>

Open in new window


Then I just do this in the next page


	if(isset($_GET['video']))
			{
			    $videoToDisplay = $_GET['video'];
			echo "href=\"http://blah.com/seiftube/videos/".$videoToDisplay."\"";	

....	

Open in new window

I know that the $link.$count was saving nothing...in C you can append an int (convert it to string fist) to a variable by using sprintf so the variable would be

$link1 =
$link2 =
$link3 =

then I could use $link1 or $link2 where I please....is a bit diff in php....cheers.