Clever -Alternating text color

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Clever -Alternating text color

Post by mohson »

Guys I already have an alternating rows function on my code but how would I go about making the text alternating as well.

SO I have two colors with the text alternating between each color?? heres my code for alterning row colors -now I want to do the same for text?

Code: Select all

// Define your colors for the alternating rows

$color1 = "#ADD8E6";$color2 = "#E0FFFF";
$color = $color2;echo 

"<table width="50%" border="0" cellpadding="2" cellspacing="2">
    <tr>
		<td><b><small>RecNo</small></b></td>
		<td><b><small>ID</small></b></td>
		<td><b><small>Title</small></b></td>
		<td><b><small>First Name</small></b></td>
		<td><b><small>Surname</small></b></td>
		<td><b><small>Organisation</small></b></td>
		<td><b><center><small>Role</small></center></b></td>
		<td><b><small>Address(1)</small></b></td>
		<td><b><small>Address(2)</small></b></td>
		<td><b><small>City</small></b></td>
		<td><b><small>Post Code</small></b></td>
		<td><b><small>Telephone</small></b></td>
		<td><b><small>Mobile</small></b></td>
		<td><b><small>Fax</small></b></td>
		<td><b><small>Last Contact</small></b></td>
		<td><b><small>Contact Again</small></b></td>
		<td><b><small>Email</small></b></td>
		<td><b><small>Notes</small></b></td>";while ($row =
mysql_fetch_object($sql)) 

{($color==$color2)? $color = $color1 : $color = $color2;


echo "<tr bgcolor="$color"><td>".$count . '</td><td> ' . $row->person_id .'</td><td>'.        
	$row->salutation .'</td><td>'.         
	$row->firstname .'</td><td>'.         
	$row->surname .'</td><td>'.        
 	$row->organisation .'</td><td>'.        
	$row->role.'</td><td>'.       
 	$row->address1 .'</td><td>'.        
	$row->address2 .'</td><td>'.       
 	$row->city .'</td><td>'.       
 	$row->postcode .'</td><td>'.        
	$row->telephone .'</td><td>'.        
	$row->mobile .'</td><td>'.        
	$row->fax .'</td><td>'.        
	$row->dateoflastcontact.'</td><td>'.        
	$row->datecontactagain  .'</td><td>'.       
 	$row->email .'</td><td>'.    
	$row->notes .'</td></tr>';

$count += 1;
}

echo "</table>";
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

if you create a style that will apply to the text, you can do this like:
<style>
color1{color:#CCCC};
color2{color:#DDDD};
</style>

after $color1 = "#ADD8E6";$color2 = "#E0FFFF";
$colorText1 ="color1";
$colorText2 ="color2";

then apply the style to your <td>'s..like <td class=\"$colorText\">
The color of text will match the style you created.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

can you show me how to do this with my code???
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

he did...
Blade556
Forum Newbie
Posts: 6
Joined: Thu Dec 23, 2004 11:03 am

Post by Blade556 »

I think mohson meant like add it to the code he showed us and make a new post with all of it together.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

meaby, but we are not the homework club that will do everything...
Blade556
Forum Newbie
Posts: 6
Joined: Thu Dec 23, 2004 11:03 am

Post by Blade556 »

I agree, but it would've been a nice gesture.

Oh where is the christmas spirit :P
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

LOL and after all his name was snicholas!!
Post Reply