rvdb86 Posted February 15, 2009 Share Posted February 15, 2009 Hi, I have the following function that lists files in a folder on my server: while (false !== ($file = readdir($dir_handle))) { if($file!="." && $file!="..") { if (is_dir($path."/".$file)) { //Display a list of sub folders. ListFolder($path."/".$file); } else { $size = filesize($path."/".$file); $sizemb = ($size / 1024)/1024; $sizemb = round($sizemb,2); $ext = substr($file, strrpos($file, '.') + 1); $temp_file = $string = substr($file, 0, -4); //$type = filetype($path."/".$file); // file //Display a list of files. echo "<tr>"; echo "<td colspan=\"3\">"; echo "<img src=\"images/$ext.gif\" border=\"0\"> $temp_file ". $sizemb . " mb"; echo "</td>"; echo "</tr>"; } } } I want that each other <tr> will be a different color. (grey, white, grey white ..etc..) I would appreciate any suggestions! Link to comment https://forums.phpfreaks.com/topic/145254-solved-need-help-with-alternating/ Share on other sites More sharing options...
allworknoplay Posted February 15, 2009 Share Posted February 15, 2009 here's a code that I use for all my projects, you basically use the "$i" since it's iterated over and over to create your rows... $check = ($i % 2); if ($check == 1) { $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#eeeeee"; } Of course you will make the BACKGROUND attribute in your TR equivalent to $bgcolor Link to comment https://forums.phpfreaks.com/topic/145254-solved-need-help-with-alternating/#findComment-762497 Share on other sites More sharing options...
rvdb86 Posted February 15, 2009 Author Share Posted February 15, 2009 wow thanks 4 the quick reply and works brilliantly!!! Link to comment https://forums.phpfreaks.com/topic/145254-solved-need-help-with-alternating/#findComment-762501 Share on other sites More sharing options...
Philip Posted February 15, 2009 Share Posted February 15, 2009 here's a code that I use for all my projects, you basically use the "$i" since it's iterated over and over to create your rows... $check = ($i % 2); if ($check == 1) { $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#eeeeee"; } Of course you will make the BACKGROUND attribute in your TR equivalent to $bgcolor Additionally, make sure to set $i equal to 1 or 0 to begin with - somewhere above your while loop. P.S. - don't forget to mark as solved Link to comment https://forums.phpfreaks.com/topic/145254-solved-need-help-with-alternating/#findComment-762502 Share on other sites More sharing options...
allworknoplay Posted February 15, 2009 Share Posted February 15, 2009 wow thanks 4 the quick reply and works brilliantly!!! Of course.... Link to comment https://forums.phpfreaks.com/topic/145254-solved-need-help-with-alternating/#findComment-762503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.