MasterACE14 Posted October 30, 2008 Share Posted October 30, 2008 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! Regards ACE Link to comment https://forums.phpfreaks.com/topic/130692-solved-shoutbox-alternating-post-colors/ Share on other sites More sharing options...
samshel Posted October 30, 2008 Share Posted October 30, 2008 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/130692-solved-shoutbox-alternating-post-colors/#findComment-678217 Share on other sites More sharing options...
MasterACE14 Posted October 30, 2008 Author Share Posted October 30, 2008 that has worked perfectly! Thanks heaps samshel Link to comment https://forums.phpfreaks.com/topic/130692-solved-shoutbox-alternating-post-colors/#findComment-678218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.