Jump to content

Table Background Row Using PHP Function


whynot

Recommended Posts

Hi,

I have This Function For Two backgrounds row of table :

function background() {
      $bg = ''; // odd 
      $bg2 = 'F3F3F3'; // even

      if ( $i%2 == 0 )
       $bgs = "$bg";
      else
       $bgs = "$bg2";
   
   return $bgs;
}

 

PHP CODE IS :

echo "<TABLE>";
$i = 0;
while ($f = $db->fetcharray( $r )) // for fetch 
{
background(); // function
echo "<tr> 
                 <td bgcolor=\"{$bgs}\">$id</td>
                 <td bgcolor=\"{$bgs}\">$name</td>
                 <td bgcolor=\"{$bgs}\">$date</td>
         </tr> ";
$i++;
}
echo "</table>";

 

But This Not Worked. What's Problem ?

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/255969-table-background-row-using-php-function/
Share on other sites

I don't see where you assign the background function so try something like

 

echo "<TABLE>";
$i = 0;
while ($f = $db->fetcharray( $r )) // for fetch 
{
$bgs = background(); // function
echo "<tr> 
                 <td bgcolor=\"{$bgs}\">$id</td>
                 <td bgcolor=\"{$bgs}\">$name</td>
                 <td bgcolor=\"{$bgs}\">$date</td>
         </tr> ";
$i++;
}
echo "</table>";

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.