homepage Welcome to WebmasterWorld Guest from 54.161.155.142
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
alternate backgrounds colours in list of links
novice needs help!
michael heraghty




msg:1250801
 4:35 pm on Sep 20, 2005 (gmt 0)

I've been trying to modify a script that lets users upload files to my site, and to view/download a list of the uploaded files.

I want to modify it so that every second list item uses a stylesheet class that makes its background a darker colour.

Here is the code that produces the list of filenames/links:

$list = "<ul>";
$dir = opendir($absolute_path);
while($file = readdir($dir)) {
if (($file!= "..") and ($file!= ".")) {
$list .= "<li><a href=\"$dl$file\">$file</a></li>";
}
}
$list .= "</ul>";
echo $list;

I want to change this so that every second list item appears as follows:

<li class="darkbg">

Any help would be greatly appreciated!

 

jatar_k




msg:1250802
 5:58 pm on Sep 20, 2005 (gmt 0)

you can use modulus and a counter

$cnt = 0; 
$list = "<ul>";
$dir = opendir($absolute_path);
while($file = readdir($dir)) {
if (($file!= "..") and ($file!= ".")) {
if ($cnt % 2) $list .= "<li><a href=\"$dl$file\">$file</a></li>";
else $list .= "<li class=\"darkbg\"><a href=\"$dl$file\">$file</a></li>";
$cnt++;
}
}
$list .= "</ul>";
echo $list;

michael heraghty




msg:1250803
 6:35 pm on Sep 20, 2005 (gmt 0)

Perfect! Thanks for the beginner's lesson, JK. Exactly what I wanted.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved