Confused

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LespaulGuy86
Forum Newbie
Posts: 2
Joined: Wed Feb 27, 2008 3:52 pm

Confused

Post by LespaulGuy86 »

Ok, I'm having trouble with the following code.

I'm trying to get it to cycle through all the files in a folder and generate a link based on the filenames that launches a javascript function. However, when I load it into mozilla firefox, I just get a white screen.

Here's the broken code.

<?php
$filePath='\news\';
$dir=opendir($filePath);
While (false !== ($file=readdir($dir))){
echo "<br />";
echo '<a href="javascript:toggleLayer(\' '.$file.'\');">testing</a>';
}
closedir($dir);

?>

The following code works, creates the link, and will launch the java script, but doesn't allow me to pass parameters to the script.

<?php
$filePath='\news\';
$dir=opendir($filePath);
While (false !== ($file=readdir($dir))){
echo "<br />";
echo "<a href=\"javascript:toggleLayer();\">$file</a>";
}
closedir($dir);

?>

And the following code works on a seperate page that I made just for testing.

<?php
$file='testing';
echo '<a href="javascript:toggleLayer(\''.$file.'\');">testing</a>';

?>

So what am I missing? Any help at all would be greatly appreciated. Thanks so much!
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: Confused

Post by EverLearning »

Your code is giving you a white page, because it has syntax error in it:

Code: Select all

$filePath='\news\';
should be

Code: Select all

$filePath='\news\\';
You had escaped single quote, and the string was not closed so php couldn't parse the file.
And by the way, in filepaths use forwardslash '/', it will be interpreted properly, even on windows. :)
Once that is corrected, it should work(it worked for me).
When developing scripts always turn error reporting on with E_ALL set, so when your scripts dies for whatever reason, you'll have some clue :)
LespaulGuy86
Forum Newbie
Posts: 2
Joined: Wed Feb 27, 2008 3:52 pm

Re: Confused

Post by LespaulGuy86 »

thanks so much...I'll try it!
Post Reply