Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    707
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Having trouble alternating row colors

    I cant figure out why it isnt working.

    I put I think all the correct things.

    Here is how it looks:

    PHP Code:
    <?php

    //alternating row colors
    $color1 "#CCFFCC"
    $color2 "#BFD8BC"
    $i 1;

    while(
    $rows=mysql_fetch_array($result)){
        
        
    if(
    $i%== 1) {
    $color $color1; }
    else { 
    $color $color2; }

    ?>
    <tr>
    <td align="center" bgcolor="<?php echo $color?>"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
    But for some reason its showing the same color for all the rows.

    Preview: http://brian.ubietymedia.com/project/

    You can see that the first row is the same color instead of alternating green and red.

    If the whole script is needed, il be glad to post it.

    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You are not incrementing $i. Change that to if ($i++ % 2 == 1), and you should see the alternating rows.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •