#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    82
    Rep Power
    12

    styles.css in php


    Hi

    I have a table with results, all rows are displayed in one colour.. as of below... but how can I get the background-color displayed every two rows only?

    tr, td {
    font-family: <?php print($VISUALS[$SkinID]['page']['font']); ?>;
    font-color: <?php print($VISUALS[$SkinID]['page']['color']); ?>;
    font-size: <?php
    print($VISUALS[$SkinID]['page']['fontsize']);
    print($VISUALS[$SkinID]['page']['fontunit']);
    ?>;
    background-color: <?php print($VISUALS[$SkinID]['page']['background-color']); ?>;
    }

    from visuals.inc:

    $VISUALS[0]['page']['background-color'] = '#E9E9E9';
    johnno
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Georgia
    Posts
    102
    Rep Power
    14
    Here's some code I use to alternate row color:

    while($row = mysql_fetch_array($result)) {
    if(($counter % 2) == 0) {
    $rcolor = "#EFEFEF";
    }
    else {
    $rcolor = "#DDDDDD";
    }
    echo"
    <tr bgcolor='$rcolor'>
    <td>

    </td>
    </tr>
    and so on......
    ";

    $counter++;
    }

    Hope this helps. I know it's not css, but it is an easy way to do it.
  4. #3
  5. funky munky
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2001
    Location
    UK
    Posts
    1,446
    Rep Power
    16
    If you setup two different CSS ids:

    .tr0 {
    background-color: <?php print($VISUALS[$SkinID]['page']['background-color0']); ?>;
    }

    .tr1 {
    background-color: <?php print($VISUALS[$SkinID]['page']['background-color1']); ?>;
    }

    then in the code where you output the rows of your table (presuming they're coming from an array of results):

    PHP Code:
    $toggle=0;
    foreach(
    $row_array as $row){    
        print(
    "<tr id=tr$toggle><td>$row[0]</td><td>$row[1]</td></tr>\n");
        
    $toggle=($toggle+1)%2;

    you should get the effect you're after (although I'm no CSS master, so you'd have to figure that out - hey what you expect on a php forum;-)

    EDIT: the $toggle=($toggle+1)%2 just sets the value of $toggle to 0 if it's current value is 1 and vice-versa.
    Last edited by munkfish; February 14th, 2003 at 06:11 PM.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    3
    Rep Power
    0
    As said above, define 2 elements iny our css file, then during the loop to get your results from the mysql db, just insert a little if statement with a counter var to exchange the colors on odd/even etc.

    Good luck to you

IMN logo majestic logo threadwatch logo seochat tools logo