Jump to content


Row coloring.. ?


6 replies to this topic

#1 Marxx

    Young Padawan

  • Members
  • Pip
  • 116 posts
  • Gender:Male
  • Location:Finland

Posted 24 January 2006 - 10:47 AM

Hello!

I use generated rows in my mainpage and i was wondering that how can i make those appear different background colors?

I was thinking that every second would be gray and every second white.


Thanks for all help!

#2 meadow

    Young Padawan

  • Members
  • Pip
  • 224 posts
  • Location:Devon, England
  • Interests:Php, Hockey, mysql, web design.

Posted 24 January 2006 - 11:56 AM

There are a few tutorials on this on pixel2life, heres a search:

http://www.pixel2life.com/tutorials/PHP_Co...5&d=1&ss=colors

#3 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 24 January 2006 - 04:23 PM

assuming you want to use PHP, this should work

// $sql here
$rowcolor = 1;
while($a=mysql_fetch_array($sql)){
echo "<table style=\"background-color:";
if ($rowcolor == 1){
echo'#FFFFFF';
} else {
echo'#CCCCCC';
$rowcolor = 0;
}
echo " \" width=\"500\"  \"><tr><td>$whatevervariableyouwanttoechohere</td></tr></table>";
$rowcolor = $rowcolor + 1;
}
?>


#4 Marxx

    Young Padawan

  • Members
  • Pip
  • 116 posts
  • Gender:Male
  • Location:Finland

Posted 24 January 2006 - 05:02 PM

Hmm.. Avalanche that is looking great! But since i'm not world best php coder, how do i modify that into this?

This little script fetch my news forum subjects and show them as links in my mainpage..

<div class="portal">
			 <h2>Uutiset</h2>			 
			  
				<table width="100%" cellpadding="0" cellspacing="0" border="0">
					  <tr>
						<?php					
					$result = mysql_query("SELECT DISTINCT t.topic_id, t.topic_title, t.topic_poster, t.topic_first_post_id, t.forum_id, t.topic_replies, u.user_id, u.username, s.post_id, s.post_text
					FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_posts_text s
					WHERE p.topic_id = t.topic_id AND t.topic_poster = u.user_id AND t.topic_first_post_id = s.post_id AND t.forum_id = 1 
					ORDER BY p.post_time desc LIMIT 5");				   

					while($r=mysql_fetch_array($result)){									   
					echo "<p class=\"newsrow\"><img src=/forum/templates/ca_aphrodite/images/post_posted.gif align=top>&nbsp;&nbsp;
					<a href=/forum/viewtopic.php?t=".$r['topic_id'].">".$r['topic_title']."</a></p>";
					}
					?> 
					  </tr>		  
				  </table>
			  
			</div>



Thanks for all help!

#5 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 24 January 2006 - 06:18 PM

<div class="portal">
<h2>Uutiset</h2>	  
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<?php
$rowcolor = 1;			  
$result = mysql_query("SELECT DISTINCT t.topic_id, t.topic_title, t.topic_poster, t.topic_first_post_id, t.forum_id, t.topic_replies, u.user_id, u.username, s.post_id, s.post_text
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_posts_text s
 WHERE p.topic_id = t.topic_id AND t.topic_poster = u.user_id AND t.topic_first_post_id = s.post_id AND t.forum_id = 1 
ORDER BY p.post_time desc LIMIT 5");				   
while($r=mysql_fetch_array($result)){
echo "<table style=\"background-color:";
if ($rowcolor == 1){
echo'#FFFFFF';
} else {
echo'#CCCCCC';
$rowcolor = 0;
}
echo " \" width=\"100% \"><tr><td><img src=/forum/templates/ca_aphrodite/images/post_posted.gif align=top>&nbsp;&nbsp;<a href=/forum/viewtopic.php?t=".$r['topic_id'].">".$r['topic_title']."</a></td></tr></table>";
$rowcolor = $rowcolor + 1;
}
?>
</tr></table></div>


#6 Marxx

    Young Padawan

  • Members
  • Pip
  • 116 posts
  • Gender:Male
  • Location:Finland

Posted 25 January 2006 - 08:21 AM

And it works perfectlly!! ^_^

Thanks Avalanche so much! You're awesome!!

#7 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 25 January 2006 - 11:02 AM

no problem, glad i could help :(





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users