NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page the simple way to do alternate row colors

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 11-23-2004, 03:29 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer

the simple way to do alternate row colors


everytime ive looked about at alternate row colors seen some long code which just isnt nesacary imo

heres the easyway, 3 variables, 1 if statement which can be nested in an iffstament
but heres the code
PHP Code:
// the variables
$bgcolor="#c0c0c0";
$bgcolor1="#EFEFEF";
$bgcolor2="#c0c0c0"// for one color leave this feild empty

// the if statment
if($bgcolor==$bgcolor1)
    {
????: NamePros.com http://www.namepros.com/code/56791-simple-way-do-alternate-row-colors.html
        
$bgcolor=$bgcolor2;
    }
    else
    {
        
$bgcolor=$bgcolor1;
    } 
heres the code in an example

PHP Code:
 echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\">";

$bgcolor="#c0c0c0";
$bgcolor1="#EFEFEF";
$bgcolor2="";
$i=0;
while(
$i 30)
{
if(
$bgcolor==$bgcolor1)
    {
        
$bgcolor=$bgcolor2;
    }
    else
    {
        
$bgcolor=$bgcolor1;
    } 
    echo 
"<tr bgcolor=$bgcolor><td>background color is $bgcolor</td></tr>";
    
$i++;
????: NamePros.com http://www.namepros.com/showthread.php?t=56791
}

echo 
"</table>"
heres a demo
http://www.crooty.co.uk/scripts/alternaterows.php

it basically says if bgcolor equals bgcolor1 set bgcolor as bgcolor 2 and then it swaps it around and does it every time
Last edited by adam_uk; 11-23-2004 at 03:34 PM.
adam_uk is offline  
Old 12-09-2004, 03:05 AM   #2 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



You can also write that like below to save yourself from writing the same thing twice and save a little coding. The ternary operator comes in handy for code like that.
PHP Code:
echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\">"
????: NamePros.com http://www.namepros.com/showthread.php?t=56791

$bgcolor1="#c0c0c0"
$bgcolor2="#EFEFEF"
$i=0

while(
$i 30) {
    
$bgcolor = ($i 2) ? $bgcolor1 $bgcolor2
    echo 
"<tr bgcolor=$bgcolor><td>background color is $bgcolor</td></tr>"
    
$i++; 
     
}
echo 
"</table>"
deadserious is offline  
Old 12-10-2004, 05:20 PM   #3 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

Originally Posted by deadserious
You can also write that like below to save yourself from writing the same thing twice and save a little coding. The ternary operator comes in handy for code like that.
PHP Code:
echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\">"

$bgcolor1="#c0c0c0"
$bgcolor2="#EFEFEF"
$i=0

while(
$i 30) {
    
$bgcolor = ($i 2) ? $bgcolor1 $bgcolor2
    echo 
"<tr bgcolor=$bgcolor><td>background color is $bgcolor</td></tr>"
????: NamePros.com http://www.namepros.com/showthread.php?t=56791
    
$i++; 
     
}
echo 
"</table>"
when i saw the thread, i was going to post something like this. i agree, this is the easiest way here
axilant is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 06:02 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger