Reputation: 44066
I am trying to print print this out in the html
<a id='riverwalk' style='display:none;' href='images/riverwalk/1.jpg' rel='prettyPhoto[riverwalk]'></a>
<a style='display:none;' href='images/riverwalk/2.jpg' rel='prettyPhoto[riverwalk]'></a>
<a style='display:none;' href='images/riverwalk/3.jpg' rel='prettyPhoto[riverwalk]'></a>
<a style='display:none;' href='images/riverwalk/4.jpg' rel='prettyPhoto[riverwalk]'></a>
But i want to do it pro grammatically and this is my code..but just not doing anything at all
$counter = 0;
$directory = "images/riverwalk"
$dir = opendir ("images/riverwalk");
while (false !== ($file = readdir($dir))) {
if ($counter == 0) {
echo "<a id='riverwalk' style='display:none;' href='images/riverwalk/$file' rel='prettyPhoto[riverwalk]'></a>";
$counter++;
}else{
echo "<a style='display:none;' href='images/riverwalk/$file' rel='prettyPhoto[riverwalk]'></a>";
$counter++;
}
}
does anything look off to anyone...i cant view the errors because i cant turn php errors on...any ideas
FIX: the issue was the a semicolon missing on the second line
Upvotes: 1
Views: 4333
Reputation: 980
$dir = './'; open_dir($dir);
function open_dir($dir = null) { global $htaccesscount;
if (!empty($dir) && is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") {
$filetype = filetype($dir . $file);
switch ($filetype) {
case 'dir' :
break;
case 'file' :
break;
}
}
}
closedir($dh);
}
}
}
Upvotes: 0
Reputation: 10912
Take a look at scandir() - it's much easier to write and debug..
$counter = 0;
$dirf = 'images/riverwalk';
$dir = scandir($dirf);
foreach($dir as $file) {
if(($file!='..') && ($file!='.')) {
if($counter==0)
echo "<a id='riverwalk' style='display:none;' href='images/riverwalk/$file' rel='prettyPhoto[riverwalk]'></a>";
else
echo "<a style='display:none;' href='images/riverwalk/$file' rel='prettyPhoto[riverwalk]'></a>";
$counter++;
}
}
If that doesn't work use is_dir() to check you're pointing at the correct directory..
Upvotes: 2
Reputation: 8509
Maybe you missed semicolon (;) in line 2 of your PHP code... Try to add ; at the and of line. This code works fine!
consider this line:
$directory = "images/riverwalk"
Upvotes: 1
Reputation: 16846
I hope I don't go too far by saying: It actually does work, but you can't see anything because your <a>
's are empty. Try it with
if ($counter == 0) {
echo "<a id='riverwalk' style='display:none;' href='images/riverwalk/$file' rel='prettyPhoto[riverwalk]'> blib </a>";
$counter++;
}else{
echo "<a style='display:none;' href='images/riverwalk/$file' rel='prettyPhoto[riverwalk]'> blub </a>";
(added 'blib' and 'blub')
If you did think of this (in that case please provide html source code in your question), tell me in a comment and I'll delete this answer.
Upvotes: 1