';
    print ';
    print ';
    print ';
    print '';
}

As you can see it was pretty simple, and as you can imagine very plain. I needed to number the list.

$i = 0;
foreach($foo as $a => $b)
{
    $i++;
    print '
';
    print ';
    print ';
    print ';
    print ';
    print '';
}That took care of the numbered rows. I thought that it would be easier to use if every other row was a diff. color. I first tried to use modulus to get the remainder of $i when divided by 2. If there was a remainder, then that row was odd. That was my thinking - but it didn't work. I found this solution (that was easy) on php.net.

$i = 0;
$alt = true;

foreach($foo as $a => $b)
{
    $i++;
    print ''.($alt?' bgcolor="#CCCCCC"':'').'>';
    print '
;
    print ';
    print ';
    print ';
    print '';
    $alt =! $alt;
}

Works like a charm :D

Source: http://community.livejournal.com/php/559698.html

    easy alternate table rows

    Date: 04/11/07 (PHP Community)    Keywords: php, database

    I had a big long report that I printed to the screen. It was a foreach loop that went through an associative array of database results and put them in a table. It looked crappy at first. This is what I had at the beginning:

    foreach($foo as $a => $b)
    {
        print '
'.$b['stuff'].''.$b['stuff'].''.$b['stuff'].'
'.$i.''.$b['stuff'].''.$b['stuff'].''.$b['stuff'].'
'.$i.''.$b['stuff'].''.$b['stuff'].''.$b['stuff'].'
« text messages || $something = $something ->... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home