Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Feb 2003
    Location
    Washington DC
    Posts
    17
    Member #
    773
    How can i alternate the row color in this php code?

    PHP Code:
     <?php
        
        $link 
    mysql_connect("localhost","root","clave");
        
    //select a database
            
    mysql_select_db("sample_db"$link);
        
        
    //requesting data
            
    $result mysql_query("SELECT id,linkname,linkaddress,username,useremail,linkdescription,linkdate FROM links ORDER BY id DESC"$link);
        if(
    $row mysql_fetch_array($result)) {
            echo 
    "<table cellpadding=\"4\" cellspacing=\"0\">";
            
            do{
                echo 
    "<tr bgcolor=$AN ALTERNATE COLOR HERE><td>";
                echo 
    "TEXT FROM MySQL";
                echo 
    "</td></tr>";
            }
            
            while(
    $row mysql_fetch_array($result));
            
            echo 
    "</table>";
        }else{
            echo 
    "<p style=\"color: red; weight: bold\">La base de datos está vacia</p>"
        }
    :dead:
    Elmer S.

  2.  

  3. #2
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    You mean alternate between two colours?

    PHP Code:
    <?php
      
    ...
      
    $Colour1 "#FF00FF";
      
    $Colour2 "#FFFF00";
      
    $count 0;     
      do {
        echo 
    "<tr bgcolor=\"";
        echo (
    $count 2) ? $Colour1 $Colour2//ALTERNATE COLOR
        
    echo "\"><td>";
        ...
        
    $count++;
      }
    ...
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  4. #3
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    Or compactly
    PHP Code:
    echo '<tr bgcolor="' . ( (($count++) % ) ? "#FF00FF" "#FFFF00" ) . '"><td>'
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  5. #4
    Junior Member
    Join Date
    Feb 2003
    Location
    Washington DC
    Posts
    17
    Member #
    773
    thanks man that does the job
    the money is your.. i'm getting poor hehe

    regards.
    Elmer S.

  6. #5
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    thx!
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:53 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com