Jump to content

[SOLVED] Need Help with alternating <tr>


rvdb86

Recommended Posts

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

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

 

 

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.