Re: alternating table entry colors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 10 Dec 2004 18:19:35 -0600, Brad Ciszewski <bradcis@xxxxxxxxxxx> wrote:
> i need some assistance making my table (rows) change color for every other
> data. here is what i have so far, but i get a "unexpected T_STRING error".
> this error's line is: if($thisRow mode 2 == 0){
> 
> +=+=+  SCRIPT BELOW  +=+=+
> 
> $thisRow = 0;
> 
> $query = mysql_query("SELECT * FROM security_images ORDER BY ID DESC");
> while($gt=mysql_fetch_array($query)){
> if($thisRow mode 2 == 0){
> $backgroundColor = "#CCCCCC";
> }else{
> $backgroundColor = "#FFFFFF";
> }
> 
> extract($gt);
> echo ?>
>  <tr bgcolor="<?PHP echo($backgroundColor); ?>">
>    <td><?PHP echo($ID); ?></td>
>    <td><?PHP echo($ipAddr); ?></td>
>    <td><?PHP echo($area); ?></td>
>    <td><?PHP echo($insertdate); ?></td>
>    <td><?PHP echo($referenceid); ?></td>
>    <td><?PHP echo($hiddentext); ?></td>
>  </tr>
>  <?PHP
>  $thisRow++
>  } ?>
> 
> +=+=+  SCRIPT ABOVE  +=+=+
> 
> thanx in advance!
> 
 How about :

<?php
$rowNum = 0;
$bg = array("#CCCCCC", "#FFFFFF");
run query
while ( query_results)
{
?>
<tr bgcolor="<?=$bg[$rowNum]?>">
  <td>...
<?php
$rowNum = ($rowNum==0)?1:0;
}
?>

I normally use a CSS stylesheet with entries called tableRow0 and
tableRow1 and then have the <TR> as:

<TR CLASS="tableRow<?=$rowNum?>">

HTH

Graham

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux