Simple Iteration Question [SOLVED w/ answer]
Posted: Tue Oct 18, 2005 6:25 am
Hi guys,
I'm really stumped at this and I know there must be a very simple solution.
I'm reading files from a dir and then printing each one into a table, I want 2 files to one row, so I need to echo <tr> and </tr> before and after every other file is printed into a column.
Here is my code:
You can see where I've attempted to implement something to do it, but it does it everytime a file is shown... lol. So I thought about changing it, but it gets too complex and hurts my brain.
Is there a simple way of doing something like this using the ternary operator?
Cheers.
I'm really stumped at this and I know there must be a very simple solution.
I'm reading files from a dir and then printing each one into a table, I want 2 files to one row, so I need to echo <tr> and </tr> before and after every other file is printed into a column.
Here is my code:
Code: Select all
//Start the table
echo '<table border="1" bordercolor="black">';
/*Initialise a new row determination variable
$newrow = "yes";*/
//Read all the files from the directory and print them all in the table
if ($handle = opendir('gallery/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
/*if ($newrow == "yes") {
echo '<tr>';
$newrow = "no";
}*/
echo '<td><center><a href="' . $file . '"><img src="gallery/' . $file . '" border="0"></a><br><i>' . $file . '</i></center></td>';
/*if ($newrow == "no") {
echo '</tr>';
$newrow = "yes";
}*/
}
}
closedir($handle);
}
//Close the table
echo '</table>';Is there a simple way of doing something like this using the ternary operator?
Cheers.