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!
Confused
Moderator: General Moderators
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Confused
Your code is giving you a white page, because it has syntax error in it:
should be
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
Code: Select all
$filePath='\news\';Code: Select all
$filePath='\news\\';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
thanks so much...I'll try it!