Results 1 to 4 of 4

Thread: How to alternate row colour using php
      
   

  1. #1
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Question 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

  2. #2
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  3. #3
    jillyronald is offline Private
    Join Date
    Sep 2010
    Posts
    4

    Default 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.

  4. #4
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Default 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>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49