How to alternate row colour using php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Rob (SA)
    Lieutenant Colonel

    • Nov 2006
    • 586

    How to alternate row colour using php

    HI Folks,

    I have a page that populates data from MySQL and I would like this page to show with rows of alternating backgrounds.

    I have got the page to work without the colours, using pretty much a cut an paste approach and therefore it requires the help of someone that is clued up to php.

    I look forward to you responses
    Kind Regards
    Rob
    www.gnjgf.co.za
    www.oryan-projects.com
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: How to alternate row colour using php

    Use this code before the loop that displays the rows:

    $bkgr_color[0] = "#FFE4E1";
    $bkgr_color[1] = "#E6E6FA";
    $color = 0;

    to set the background color for the rows.

    In the cell code, which looks like
    echo '<table.......>';

    for(............){

    echo '<tr>
    <td ................>
    </tr>';
    }


    add

    <td ................ bgcolor="'.$bkgr_color[$color].'">


    Then, at the end of the loop code (before the } loop closing tag add this.

    $color++;
    if($color >1){
    $color = 0;
    }
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • jillyronald
      Private

      • Sep 2010
      • 4

      #3
      Re: How to alternate row colour using php

      Above coding is very good and needed for alternate row colour. I was prepared so many wesites in php, this coding helps to make different types of colour in php page. I am appriciate to you because with this coding I created a very attractive home page of my website.

      Comment

      • Rob (SA)
        Lieutenant Colonel

        • Nov 2006
        • 586

        #4
        Re: How to alternate row colour using php

        Hi George,

        Thanks for the info.

        Could you perhaps help in showing me exactly where in this script it should go ?

        PHP Code:
        <tr> 
        <th class="head_cell">CELL NUMBER</th> 
        <th class="head_cell">SURNAME, NAME</th> 
        <th class="head_cell">EMAIL</th> 
        </tr> 
        <?php 
        while($row=mysql_fetch_array($result))

        ?> 
        <tr>
        <td class="result_cell c_align"><?php echo $row['cell_phone'];?></td> 
        <td class="result_cell back_color"> 
        <option value="<?php echo strtoupper ($row['surname'] . ', ' $row['name']);?>"><?php echo strtoupper($row['surname'] . ', ' $row['name']);?></option> 
        </td> 
            
        <td class="cell_other back_color2">
        <a href="mailto:<?php echo $row['email'];?>"><?php echo $row['email'];?></a> 
        </td>
        </tr> 

        <?php 
            
        if(!isset($counter[$firstNAsAString])) { 
                
        $counter[$firstNAsAString] = 0
            } else { 
                
        $counter[$firstNAsAString]++; 
                
        $last_surname $row['surname']; 
                
        $i++; 
        ?>
        </td>
        </tr> 
        <?php 
            


        ?> 
        </table>
        Kind Regards
        Rob
        www.gnjgf.co.za
        www.oryan-projects.com

        Comment

        Working...
        X