| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | Oh my God I am confused I swear, my head is going to split, I am SO confused right now I'm about to yank my effing hair out. Okay, so I have this to work with (and keep in mind I know just about jack for PHP and I'm not even halfway finished with a book on it). Code: <?
//get directory handle
$hook = opendir("icons");
//read directory and echo list
while (($file = readdir($hook)) !== false)
{
if ($file != "." && $file != "..")
{
//set up full path
$path = $location."/".$file;
//check for directory
if (is_dir($path))
{
echo "<a href=aim:BuddyIcon?src=http://www.iming.org/imsite/gallery/icons/$file><img src=http://www.iming.org/imsite/gallery/icons/$file border=0></a>";
} else {
echo "<a href=aim:BuddyIcon?src=http://www.iming.org/imsite/gallery/icons/$file><img src=http://www.iming.org/imsite/gallery/icons/$file border=0></a>";
}}}
//close directory
closedir($hook);
?>
Code: echo "<table>";
echo "<tr>";
$counter = 0;
while ( stuff to display)
{
// start a new row
if ($counter == 5)
{
echo "</tr><tr>";
}
echo "<td> stuff ... </td>";
// add 1 to counter, or go back to 1
$counter = ($counter + 1) % 5;
}
// need to fill up last row with empty columns
while ($counter < 5)
{
echo "<td></td>";
++$counter;
}
// close row and table
echo "</tr>";
echo "</table>";
Does anyone know how I am supposed to make the second script go with the first one? Will give 75 NP$ to anyone that can help me sort this out, sorry for sound like a bumbling idiot. Thanks in advance, Andy |
| |
| | #2 (permalink) |
| You are here: X | Just replace the while loop in your script with the one provided. Add the print/echo statments for the table and then change ( stuff to display ) to (($file = readdir($hook)) !== false) Then at the end of the loop add the print / echo to close the table.
__________________ |
| |
| | #3 (permalink) |
| Senior Member | It's working but it's got a glitch in it I did what you recommended Tres, and it's working somewhat now - but it's making faulty code right now. Here's the coding: Code: <?
//get directory handle
$hook = opendir("icons");
//start the table
echo "<table>\n";
echo "<tr>\n";
$counter = 0;
//read directory and echo list
while (($file = readdir($hook)) !== false)
{
// start a new row
if ($counter == 5)
{
echo "</tr>\n<tr>\n";
}
echo "<td>\n<a href=\"aim:BuddyIcon?src=http://www.iming.org/imsite/gallery/icons/$file\">\n<img src=\"http://www.iming.org/imsite/gallery/icons/$file\" border=0></a></td>\n";
// add 1 to counter, or go back to 1
$counter = ($counter + 1) % 5;
// need to fill up last row with empty columns
while ($counter < 5)
{
echo "<td></td>\n";
++$counter;
}
// close row and table
echo "</tr>\n";
echo "</table>\n";
}
//set up full path
$path = $location."/".$file;
//check for directory
if (is_dir($path))
//close directory
closedir($hook);
?>
Code: <table> <tr> <td> <a href="aim:BuddyIcon?src=http://www.iming.org/imsite/gallery/icons/."> <img src="http://www.iming.org/imsite/gallery/icons/." border=0></a></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </tr> <tr> <td> <a href="aim:BuddyIcon?src=http://www.iming.org/imsite/gallery/icons/.."> <img src="http://www.iming.org/imsite/gallery/icons/.." border=0></a></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </tr> <tr> <td> <a href="aim:BuddyIcon?src=http://www.iming.org/imsite/gallery/icons/nfsupport.gif"> <img src="http://www.iming.org/imsite/gallery/icons/nfsupport.gif" border=0></a></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </tr> <tr> <td> <a href="aim:BuddyIcon?src=http://www.iming.org/imsite/gallery/icons/nfsupport3.gif"> <img src="http://www.iming.org/imsite/gallery/icons/nfsupport3.gif" border=0></a></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> <img src="http://www.iming.org/imsite/gallery/icons/." border=0></a></td> as an image when it shouldn't be at all, and why it's not making any of the Tables proper (like: </tr> </table> </tr>)? Thanks, Andy Last edited by AndyM3; 11-04-2005 at 04:01 PM. |
| |
| | #4 (permalink) |
| You are here: X | "." & ".." are directories. "." is the current dir and ".." is the parent. If you will not have any sub-directories, you can us is_file(), otherwise you should check for the "." or ".." shortcuts. Add If ($file !== "." and $file !== "..") or if(is_file($file) after while statement. You should replace Code: while ($counter < 5)
{
echo "<td></td>\n";
++$counter;
}
for the correct HTML, you need to add a "<table>" at the top of your loop or move the closing "</table>" to after the loop.
__________________ |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I am still to be confused regarding... | Dave in Carthage | The Break Room | 6 | 10-26-2005 09:26 PM |