Jump to content

[SOLVED] Need Help with alternating <tr>


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.