NameSilo

Oh my God I am confused

Spaceship Spaceship
Watch
Impact
45
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); 
?>

Since I basically have no idea how it could be used with a five-columned table, some guy told me to use this:
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>";

Well, I have no idea on earth how the hell the code he gave me is to be used with the first script is supposed to go. I have tried in every single way, shape, and form that I know of to try and get the two to work as one. But nope, I get parse error after parse error after parse error.

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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
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.
 
0
•••
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); 
?>

This however is the HTML it is outputing:
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>

Any ideas why it is making the code: <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>
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:
0
•••
"." & ".." 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;
}

with echo '<td colspan="5"'><td>';

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.
 
0
•••
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back