Jump to content

[SOLVED] Shoutbox, alternating post colors


MasterACE14

Recommended Posts

I've just made a Shoutbox, its working perfectly fine. But I want to have the posts text color alternating. like 1, 2, 1, 2 , where 1 will be blue for example, and 2 is white.

 

so it looks like this now.....

[Oct 30th, 1:42] ACE - lololol,olol

[Oct 30th, 1:41] ACE - weghhhhhhhhh

[Oct 30th, 1:39] ACE - lolololol Language Filter Works ****

[Oct 30th, 1:39] ACE - **** YOU

 

but I'm wondering how do I make it look like this...

[Oct 30th, 1:42] ACE - lololol,olol

[Oct 30th, 1:41] ACE - weghhhhhhhhh

[Oct 30th, 1:39] ACE - lolololol Language Filter Works ****

[Oct 30th, 1:39] ACE - **** YOU

 

here is my code.

<?php
$rs = mysql_query("SELECT * FROM `shoutbox` ORDER BY `posttime` desc") or die("select query: ".mysql_error());

echo "<div id=\"shout\">";
// loop through records writing a table for each one
while ( $row = mysql_fetch_array( $rs ) )
{
$datetime = $row['posttime'];
$year = substr( $datetime, 0, 4 );
$mon = substr( $datetime, 4, 2 );
$day = substr( $datetime, 6, 2 );
$hour = substr( $datetime, 8, 2 );
$min = substr( $datetime, 10, 2 );
$sec = substr( $datetime, 12, 2 );
$orgdate = date("F j, Y",
mktime( $hour, $min, $sec, $mon, $day, $year ) );
echo "[";
echo date("M jS, G:i", strtotime($datetime));
echo "] ";
echo $row['poster'];
echo " - ";
echo $row['text'];
echo "<br />";
} // end while
echo "</div>";
?>

 

Any help is appreciated. Thank you!  :D

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/130692-solved-shoutbox-alternating-post-colors/
Share on other sites

Code is not tested...try this.

<?php
$rs = mysql_query("SELECT * FROM `shoutbox` ORDER BY `posttime` desc") or die("select query: ".mysql_error());

echo "<div id=\"shout\">";
$intCounter = 0;
// loop through records writing a table for each one
while ( $row = mysql_fetch_array( $rs ) )
{
if($intCounter % 2) $strColor = "blue"; else $strColor = "white";
$datetime = $row['posttime'];
$year = substr( $datetime, 0, 4 );
$mon = substr( $datetime, 4, 2 );
$day = substr( $datetime, 6, 2 );
$hour = substr( $datetime, 8, 2 );
$min = substr( $datetime, 10, 2 );
$sec = substr( $datetime, 12, 2 );
$orgdate = date("F j, Y",
mktime( $hour, $min, $sec, $mon, $day, $year ) );
echo "<span style='color: ".$strColor.";'>";
echo "[";
echo date("M jS, G:i", strtotime($datetime));
echo "] ";
echo $row['poster'];
echo " - ";
echo $row['text'];
echo "</span><br />";
$intCounter++;
} // end while
echo "</div>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.