Page 1 of 1

Displaying data according to color scheme

Posted: Thu Oct 10, 2002 1:42 pm
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 :)

Posted: Thu Oct 10, 2002 1:47 pm
by volka
this might be useful
viewtopic.php?t=38

Posted: Thu Oct 10, 2002 1:53 pm
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..

Posted: Fri Oct 11, 2002 4:34 am
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