TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   list populating proplem (http://www.talkphp.com/absolute-beginners/2928-list-populating-proplem.html)

Peuplarchie 06-08-2008 08:22 PM

RESOLVED -- list populating proplem
 
Good day to you all,
I'm working of an auto-populated unordered list.
The way it working I have a recursive directory lister that list all folder in an unordered list.

My problem with that script is hat it start the listing by a ul, how can I stopt it to do so ?

PHP Code:


function dirlist($dir
{     
 
        
$dh opendir($dir); 
        
// the trick is creating the appropriate list tags 
        // before and after the loop 
        // however if the folder is empty then there shouldn't
        // be any UL tags. $isleaf keeps track of that
        
$isleaf=true;
        while((
$file readdir($dh)) !== false
        { 
                if(
$file == "." || $file == ".."
                        continue; 
                
$filed $file;
                
$file $dir "/" $file;
                if(
is_dir($file)) 
                { 
                
                        if (
$isleaf) { $isleaf=false; echo "<ul>\r"; }
                        echo 
"<li><a href=\"http://test.com/test_images.php?folder=$file\" class=\"blue0\">$filed</a></li>\r"

                        
dirlist($dir."/".$filed);

 
               }
        } 
        if (!
$isleaf) echo "</ul>\r"


}    
dirlist ("Pictures/Pics/Pic-S"); 

Thanks for you time !
Take care !

Orc 06-08-2008 08:50 PM

Quote:

Originally Posted by Peuplarchie (Post 15412)
Good day to you all,
I'm working of an auto-populated unordered list.
The way it working I have a recursive directory lister that list all folder in an unordered list.

My problem with that script is hat it start the listing by a ul, how can I stopt it to do so ?

PHP Code:


function dirlist($dir
{     
 
        
$dh opendir($dir); 
        
// the trick is creating the appropriate list tags 
        // before and after the loop 
        // however if the folder is empty then there shouldn't
        // be any UL tags. $isleaf keeps track of that
        
$isleaf=true;
        while((
$file readdir($dh)) !== false
        { 
                if(
$file == "." || $file == ".."
                        continue; 
                
$filed $file;
                
$file $dir "/" $file;
                if(
is_dir($file)) 
                { 
                
                        if (
$isleaf) { $isleaf=false; echo "<ul>\r"; }
                        echo 
"<li><a href=\"http://test.com/test_images.php?folder=$file\" class=\"blue0\">$filed</a></li>\r"

                        
dirlist($dir."/".$filed);

 
               }
        } 
        if (!
$isleaf) echo "</ul>\r"


}    
dirlist ("Pictures/Pics/Pic-S"); 


Thanks for you time !
Take care !

What do you mean? Started by ul? Also, you just need one $file == "." no need for the same with the ..

Peuplarchie 06-08-2008 08:57 PM

I meant, if I run the script it will first display an <ul>
I need it to strat with the ;

PHP Code:


if ($isleaf) { $isleaf=false; echo "<ul>\r"; } 
                        echo 
"<li><a href=\"http://test.com/test_images.php?folder=$file\" class=\"blue0\">$filed</a></li>\r"

The <ul> for the first level is already open before in the page.
this piece of code is only for the next level of folder.

Orc 06-08-2008 08:59 PM

Quote:

Originally Posted by Peuplarchie (Post 15416)
I meant, if I run the script it will first display an <ul>
I need it to strat with the ;

PHP Code:


if ($isleaf) { $isleaf=false; echo "<ul>\r"; } 
                        echo 
"<li><a href=\"http://test.com/test_images.php?folder=$file\" class=\"blue0\">$filed</a></li>\r"

The <ul> for the first level is already open before in the page.
this piece of code is only for the next level of folder.

So I think i see what your trying to do, you're trying to set $isleaf to false so that the condition will stop, and ul wont show up? correct?

delayedinsanity 06-08-2008 10:17 PM

If your page already has an opening <ul> set in the HTML, just remove it, or remove the one from the script where it says echo"<ul>\r";...?
-m

Peuplarchie 06-09-2008 12:22 AM

Orc, you are right.
Delayedinsanity, i need the echo"<ul>\r";...is needed for different level.

Peuplarchie 06-09-2008 12:24 AM

Orc only on the first level

Orc 06-09-2008 09:02 AM

Quote:

Originally Posted by Peuplarchie (Post 15421)
Orc only on the first level

Yeah, well it doesn't work that way. :P I think you should try this, just woke up so I'm a bit bleh.

PHP Code:


<?php

if ( !empty( $file ) ) { echo "<ul>\r"; }


?>



All times are GMT. The time now is 08:44 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0