[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 11-03-2005, 05:48 PM   #1 (permalink)
Senior Member
 
Ringr's Avatar
 
Join Date: Jul 2004
Posts: 1,391
1,090.86 NP$ (Donate)

Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold


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); 
?>
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
Ringr is offline  
Old 11-04-2005, 12:05 PM   #2 (permalink)
You are here: X
 
tres's Avatar
 
Join Date: Oct 2003
Location: US
Posts: 437
1.25 NP$ (Donate)

tres is just really nicetres is just really nicetres is just really nicetres is just really nice


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.
__________________
tres is offline  
Old 11-04-2005, 03:41 PM   #3 (permalink)
Senior Member
 
Ringr's Avatar
 
Join Date: Jul 2004
Posts: 1,391
1,090.86 NP$ (Donate)

Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold


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 by AndyM3; 11-04-2005 at 04:01 PM.
Ringr is offline  
Old 11-12-2005, 07:47 AM   #4 (permalink)
You are here: X
 
tres's Avatar
 
Join Date: Oct 2003
Location: US
Posts: 437
1.25 NP$ (Donate)

tres is just really nicetres is just really nicetres is just really nicetres is just really nice


"." & ".." 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.
__________________
tres is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 06:10 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85