Reply
Problem alternating background
Old 04-17-2005, 09:29 AM Problem alternating background
Junior Talker

Posts: 4
I've started making a shoutbox and wanted to get alternating backgrounds but it doesn't seem to work :S
This is my code:

Code:
<?php

$iplogging = 1;
$ipfile = "ips.txt";
$today = date("D M j G:i:s T Y");
		$ipl = fopen("$ipfile", "a");

		fwrite($ipl, "
Name: $name
Date: $today
Ip: $REMOTE_ADDR
Browser: $HTTP_USER_AGENT" 
);

$datfile = "shout.html";
$MAX_LENGTH = 3500;
$NUM_COMMENTS = 1000;


if (!$name)
{ $name = "Gast"; }
else $name .= "";

$c = preg_replace("/</","&lt;",$c);
$c = preg_replace("/>/","&gt;",$c); 
$c = str_replace(":)","<img src='smilies/smile.gif'>",$c);
$c = str_replace(":smiley:","<img src='smilies/smile-2.gif'>",$c);
$c = str_replace(":s","<img src='smilies/wacko.gif'>",$c);
$c = str_replace(":unsure:","<img src='smilies/unsure.gif'>",$c);
$c = str_replace(":p","<img src='smilies/toung.gif'>",$c);
$c = str_replace("|-)","<img src='smilies/suspicious.gif'>",$c);
$c = str_replace(";)","<img src='smilies/wink.gif'>",$c);
$c = str_replace(":worried:","<img src='smilies/worried.gif'>",$c);
$c = str_replace("O_o","<img src='smilies/weird.gif'>",$c);
$c = str_replace(":(","<img src='smilies/sad.gif'>",$c);
$c = str_replace(":yuck:","<img src='smilies/sick.gif'>",$c);
$c = str_replace(":(","<img src='smilies/sad.gif'>",$c);
$c = str_replace(":triest:","<img src='smilies/sad-2.gif'>",$c);
$c = str_replace("8)","<img src='smilies/rolleyes.gif'>",$c);
$c = str_replace("x)","<img src='smilies/push.gif'>",$c);
$c = str_replace(":|","<img src='smilies/oh.gif'>",$c);
$c = str_replace(":o","<img src='smilies/amazed.gif'>",$c);
$c = str_replace(":nuts:","<img src='smilies/nuts.gif'>",$c);
$c = str_replace(":noworry:","<img src='smilies/noworry.gif'>",$c);
$c = str_replace(":notrust:","<img src='smilies/notrust.gif'>",$c);
$c = str_replace(":@","<img src='smilies/mad.gif'>",$c);
$c = str_replace(":lol:","<img src='smilies/laugh.gif'>",$c);
$c = str_replace(":?:","<img src='smilies/huh.gif'>",$c);
$c = str_replace(":blozen:","<img src='smilies/embarrest.gif'>",$c);
$c = str_replace(":blijter:","<img src='smilies/crying.gif'>",$c);
$c = str_replace("(h)","<img src='smilies/cool.gif'>",$c);
$c = str_replace(":cheesy:","<img src='smilies/cheesy.gif'>",$c);
$c = str_replace(":D","<img src='smilies/bigsmile.gif'>",$c);
$comfile = file($datfile);
if ($c != "") {
if (strlen($c) < $MAX_LENGTH) {
$fd = fopen ($datfile, "w");
$c = stripslashes($c);


  if(($i%2)==0)
  {
    $bgcolor='#333333';
  }
  else
  {
    $bgcolor='#666666';
  }  
  fwrite ($fd, 
 "<tr bgcolor=$bgcolor align=\"left\">
<td><b><font color=\"#FF3300\">$name</font></b><font size =-2>($REMOTE_ADDR)</font><font color=\"FF3300\">:</font> $c</td>
   </tr>\n");


for ($i = 0; $i < $NUM_COMMENTS; $i++) {
fwrite ($fd, $comfile[$i]);
}
}
fclose($fd);
}
Header("Location: $HTTP_REFERER");



?>
hope someone can correct my mistake
lithium is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-17-2005, 03:15 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Do you mean for each cell of a table? Sorry i couldn't be bothered to look through the code

This is how i combat the problem.

First off i have a loop dynamically creating each row (or <TR>), adding in the information needed.

Then, before the loop begins, claim a variable $x (or watever) and set that to '1'.

Here's the tricky bit, name the class of your <TR> or each <TD> (class as in CSS) as <TR CLASS=\"ColourBackground" . $CSSNo . "\">
This will mean that we need an if statement in the loop to control what number (1 or 2) is going to be contained in $CSSNo depending on the incrementing $x variable.

Hope you're following this! So, the if statement we need, within the loop is if($x%2): $CSSNo = "1"; else: $CSSNo = "2"; endif;

This checks to see if $x is an odd or even number.

Finally, when all operations within the loop are done, as $x++; so it increments the $x variable after every loop.

So you need 2 CSS classes, one named ColourBackground1 and ColourBackground2 and add the various crudentials in that you need

Hope that's sorta clear, im in a hurry
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites: www.festerband.com | www.thegourmetpatisserie.co.uk
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem alternating background
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10734 seconds with 12 queries