• BOOKMARK

  • ADD TO FAVORITES

  • REFERENCES


  • MARC

    Mailing list ARChives
    - Search by -
     Subjects
     Authors
     Bodies





    FOLDOC

    Computing Dictionary




  • Text Link Ads






Alternating row colors tutorial

PHP Tutorials.

Alternating row colors tutorial

New postby Cat on Sat Dec 28, 2013 4:23 pm

Sometimes, when we work with tables, we probably want to change the color for every row (<td>).
There are many ways to do this, but I will describe the most simple ways.

So... let's say we have an array with 26 elements. But we don't really know that, so we do a `$count = count($myarray);`.
Good! Now we know how many elements the array has, so let's get to the point.

We want to print every element on a line, in a row. So ... we will do something like the following:


Example:
Code: [Select all] [Expand/Collapse] [Download] (Untitled)
<html>
<head><title>gee</title></head>
<body bgcolor="#FFFFFF">
<table width="100%">

<?php

// Let's say the array exists. as I said, it has 26 elements.
$array = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "26");

$count = count($array);
for($x=0;$x<=$count;$x++) {
        if(($x % 2) == 0) { $c = "#9999CC"; }
        else { $c = "#CCCCCC"; }
?>
<tr><td bgcolor="<?= $c ?>">
<?= $array[$x]; ?>
</td></tr>
<? } ?>
</table>
</body>
</html>




Anyone who wishes to make additions or changes to this tutorial email them to webmaster@linuxguruz.com
User avatar
Cat
 
Posts: 15
Joined: Thu Dec 26, 2013 7:21 pm

Return to PHP Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

  • MORE RESOURCE


  • Linux

    The Distributions





    Linux

    The Software





    Linux

    The News



  • MARKETING






  • Toll Free