Alternating row colors
Changing colours for each row with code.
Category: Coding
Views: 1512

Alternating row colors Alternating row colors

What is alternating row colors?
- Alternating row colours is when every second value is a different color.

Code:
$i = 0;
if($i==0){
$background = 'black';
}
else{
$background = 'white';
}
?>
This is our main code, this checks what $i is equal to and if it is 0 the background is black and if it is not then it is white.

- black
- white
- black
- white
and so on..

Now for the second part we need to increse and decrease the value of $i so it will loop through the background colors.

Code:
$i = 0;
if($i==0){
$background = 'black';
$i ;
}
else{
$background = 'white';
$i--;
}
?>
Now all we have added is $i and $i-- we need to do this otherwise it wouldent loop properly. $i-- will set $i to 0 and $i will set $i to 1.

If you would like more help with this tutorial please register and visit the forum.

About Michael

Michael Dunlop Michael Dunlop personal statement

“But I am already older than 21”, I hear you cry. Don’t worry, despite the name, the information and advice is more geared towards retiring prior to having a fake hip installed.

Website Sponsors
Recommended Websites
They Buy, Build, Upgrade and Sell Websites.
 
Advertise Here
Feature Interviews
Graham went from $100 one day to ... Read more
Paul Bourque started affiliate marketing less than ... Read more
Interview with Yaro Starak of Entrepreneurs-Journey.com is ... Read more
Recommended Resources
 
 
 
 
 
Get Retire at 21's FREE Secrets
Find out how I'm going to Retire VERY Early Subscribe for my Free Secrets Privacy Guaranteed. 100% Spam free.