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!
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.
//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>';
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.
Last edited by jayshields on Tue Oct 18, 2005 8:41 am, edited 1 time in total.
actually it'sthe modulas operator.. 3 % 2=1, 4%2=0, get it?:-D
essentially after you get two columns start a new row is what it's doing in your code i do believe?
edit: more thourough explanation, 3 divided by 2 is 1 with a remainder of 1 and 4 divided by 2 is 2 with a remainder of 0.hence, my answers.