for ( $i=0; $i<=1; $i++ ) {
// Displays alternate table row colors
$bg1 = "#efefef"; // color one
$bg2 = "#ffffff"; // color two
$table1 = "<tr></tr><td bgcolor=\"$bg1\">";
$table2 = "<tr></tr><td bgcolor=\"$bg2\">";
$endtab = "</td></tr>";
}
if ( $i%2 ) {
.... $table1 code ...
} else {
.... $table2 code ...
}
1) your for loop.... your if $i%2 is not inside your for loop.... so i don't see how this would work
2) your <tr></tr><td> doesn't make sense
3) you are setting tag each time... so every loop... if were happening.. you would obverwrite your old data you want to use
$tags .= not $tags =
4) you can use the more friendly FLOCK_EX and FLOCK_UN syntax... don't have to but you should not use the string rep of "2" at least use 2
flock( $fp, FLOCK_EX );
my code:
there was a small type-o in my code: an extra space after the EOS that was invisible, that and my while(1) were lethal....
here is a correct version of my code that i actually tested
<table>
<?php
$toggle = TRUE;
for ( $i=0; $i<10; $i++ ) {
$color = ( $toggle ) ? "#efefef" : "#ffffff";
print <<<EOS
<tr bgcolor="{$color}"><td>ROW {$i} </td></tr>
EOS;
$toggle = !$toggle;
}
?>
</table>
your code:
here is what i believe to be a fixed version of your code useing your method:
<table>
<?php
$url = 'http://fakeurl';
$tagdate = '3000-02-03';
$name = 'ednark';
$comment = 'hope this works';
$oldtags = '<tr><td>OLD TAGS</td></tr>';
$bg1 = "#efefef"; // color one
$bg2 = "#ffffff"; // color two
//$fp = fopen ("$filename", "w+"); // opens $filename for reading & writing
for ( $i=0; $i<10; $i++ ) {
$bg = ($i%2) ? $bg1 : $bg2;
$tags .= <<<END_TAGS
<tr>
<td bgcolor="{$bg}">
<span class="tagit">
<b><a href="{$url}" target="_blank" class="tag" onMouseover="showtip(this,event,'Posted: {$tagdate}')" onMouseout="hidetip()">{$name} $i</a></b>: {$comment}
</span>
<br>
</td>
</tr>
{$oldtags}
END_TAGS;
}
echo $tags;
//flock( $fp, "2" );
//fwrite ( $fp, $tags); // writes post to $filename
//flock( $fp, "3" ); // Unlocks File for all processes again.
//fclose ( $fp );
?>
</table>