Welcome to WebmasterWorld Guest from 54.146.174.220

Forum Moderators: coopster & jatar k

alternate backgrounds colours in list of links

novice needs help!

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

10+ Year Member



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!

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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;
6:35 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month