Displaying data according to color scheme

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
Reed
Forum Newbie
Posts: 3
Joined: Thu Oct 10, 2002 1:42 pm

Displaying data according to color scheme

Post by Reed »

Hi,

I'm having problems displaying my classified ads according to a specifc format.

Basically, the data will be shown in a similar fashion like this forum. However i would like the display box to alternate in color.

Heres a rough template of what i mean:

----------------------------------------------

POST 1 (Light blue as backgroung(BG) color)

---------------------------------------------

POST 2 ( Dark blue as BG color)

---------------------------------------------

POST 3 (Light blue as BG color)

----------------------------------------------

The BG color keeps alternating in this fashion until all the post are displayed.

Do i use html to design the color format first?

Would appreciate it if someone could give me an outline of the script to set me in the right direction.

Thanks :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

this might be useful
viewtopic.php?t=38
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

here is how i'd do it, assuming you use mysql and are familiar with it..

Code: Select all

$qry = mysql_query("SELECT * FROM ads");
$x = 0;
$color1 = "FF0000";
$color2 = "CC0000";

	echo '<table>';
	while($data = mysql_fetch_assoc($qry))&#123;
		if(($x % 2) != 0)&#123;
		echo '<tr><td bgcolor="'.$color1.'">';
		echo $data&#1111;'thing'];
		echo '</td>';
		&#125; else &#123;
		echo '<td bgcolor="'.$color2.'">';
		echo $data&#1111;'thing'];
		echo '</td></tr>';
		&#125;
		$x++;
	&#125;
	echo '</table>';
does this make sense? you're going to use a loop that increments a number on each pass, and you'll see if the number is even or odd to determine it's background color..
Reed
Forum Newbie
Posts: 3
Joined: Thu Oct 10, 2002 1:42 pm

Post by Reed »

volka
Thanks alot for the link. just what i needed.

hob_goblin
I had something vaguely similar in mind. And your coding made it so much clearer now. Thanks mate
Post Reply