Jump to content


Alternating Font Colours (Shout Box)


2 replies to this topic

#1 vexatomic

    Young Padawan

  • Members
  • Pip
  • 27 posts

Posted 08 January 2005 - 08:51 AM

<?


mysql_connect("localhost","illusion_lloyd","world");

mysql_select_db("illusion_vexatomic");

$result = mysql_query("select * from tag order by id desc");

while($r=mysql_fetch_array($result))

{

$name=$r["name"];

$message=$r["message"];

$site=$r["site"];

$id=$r["id"];

$row = 400;
$x = 1;

while ($x <= $row) {
if($id%2): $color = "#FFFFFF"; else: $color = "#000000"; endif;

echo "<CENTER><FONT COLOR=$color>
+ $name +<BR><I>$site</I><BR>$message<BR>--------------<BR></font><br><meta http-equiv='Refresh' content='30; url=tagger.php'>";

}

?>

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

Ok, so I want posts that enter my shoutbox to be in alternating font colours from row to row of the mysql database. but i don't want to make a table in the shoutbox if i can help it.

Any help?
ta in advance :)

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 09 January 2005 - 01:54 AM

<?
mysql_connect("localhost","edit","edit");
mysql_select_db("illusion_vexatomic");

$result = mysql_query("select * from tag order by id desc");

while($r=mysql_fetch_array($result)){ 

$name=$r["name"];
$message=$r["message"];
$site=$r["site"];
$id=$r["id"];

if($color = "#000000"): $color = "#FFFFFF"; else: $color = "#000000"; endif; 

echo "<CENTER><FONT COLOR=$color>
+ $name +<BR><I>$site</I><BR>$message<BR>--------------<BR></font><br><meta http-equiv='Refresh' content='30; url=tagger.php'>";
}
?>

well, i don't know if you were getting any errors or wha twas happening... you faild to explain/show us what's going on, but maybe this code could help you a little bit

p.s. next time you post something dealing with mysql, it would be wise of you to leave out this info: mysql_connect("localhost","edit","edit"); (anybody could hack in to your database with it and have free reign...), so if you were smart you'd edit it out of your post before to many ppl see it, and then (if you use the code i posted), edit your info back in before using the script

#3 Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 09 January 2005 - 02:01 PM

 <?
  //BEGIN SQL QUERY
  mysql_connect("localhost","username","password");
  mysql_select_db("illusion_vexatomic");
  $result = mysql_query("select * from tag order by id desc");

  //START THE FIRST LOOP
  while($r=mysql_fetch_array($result))
 	 {
 	 //ASSIGN VARIABLES
 	 $name=$r["name"];
 	 $message=$r["message"];
 	 $site=$r["site"];
 	 $id=$r["id"];
 	 
 	 //ASSIGN $ROW AND $X
 	 $row = 400;
 	 $x = 1;

  //START SECOND LOOP
  while ($x <= $row) 
 	 {
  if($id%2): $color = "#FFFFFF"; else: $color = "#000000"; endif;

  echo "<CENTER><FONT COLOR=$color>
  + $name +<BR><I>$site</I><BR>$message<BR>--------------<BR></font><br><meta http-equiv='Refresh' content='30; url=tagger.php'>";

  //INCREASE $X BY ONE (ADDED BY JAYMZ)
  $x++;
  //END JAYMZ'S ADDITIONS
 	 }
?>


That should solve your problem, if you need help understanding what I did let me know. :P BTW I tried to add comments that'll help you with debugging later :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users