Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Build dynamic links

Posted on 2011-10-16
4
Medium Priority
?
229 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:doyle007
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1600 total points
ID: 36977616
You're not saving anything.  You have only one variable named $link and I don't know how you can assign $link.$count = $file;  That doesn't make any sense.  You could make $link and array and use $link[$count]=$file.
0
 
LVL 7

Assisted Solution

by:Sandeep Kothari
Sandeep Kothari earned 400 total points
ID: 36977733
you can do something like this ...
replace $link.$count = $file; with this ...

$tmp = "link".$count;

$$tmp = $file;

should work...
0
 

Author Comment

by:doyle007
ID: 36977795
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

0
 

Author Closing Comment

by:doyle007
ID: 36977801
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question