On Fri, 10 May 2002, Glenn Sieb wrote:

> Thanks for all the hints--here's what my boss and I eventually came 
> out with:

This could use a few tweaks.  First off, putting mysql_num_rows in the
actual for loop executes it every iteration.  Bad.  Second, consider 
giving your code some readability by returning an associative array.
You also duplicate your if statements for company name.  You can also
rotate your column in the same IF statement to rotate the color.  Try 
this (I'll assume column names...):

----------------------------- CUT HERE -----------------------------
$sPrevCompany = $sColor = '';
while ($aRow = mysql_fetch_assoc($stmt))
{
  $sCompanyName = $aRow['companyname'];

  // If our previous company name is the same as this one, don't print
  // the company name, but print the data.
  if ($sPrevCompany == $sCompanyName)
  {
    $sColor = ($sColor == 'FF') ? '00' : 'FF';
    $sCompanyName = ' '
  }

  // We're past our if statement, so save the previous company for
  // nex time.
  $sPrevCompany = $aRow['companyname'];

  print
    "<TR BGCOLOR=#FFFF$sColor>\n".
    "\t<TD>$aRow[somecolumn]</TD>\n".
    "\t<TD>$sCompanyName</TD>\n".
    "\t<TD>$line[anothercolumn]</TD>\n".
    "</TR>\n";
}
----------------------------- CUT HERE -----------------------------

And done.  Infinitely more maintainable.

-- 
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Shaun M. Thomas                INN Database Administrator           |
| Phone: (309) 743-0812          Fax  : (309) 743-0830                |
| Email: [EMAIL PROTECTED]    AIM  : trifthen                      |
| Web  : www.townnews.com                                             |
|                                                                     |
|     "Most of our lives are about proving something, either to       |
|      ourselves or to someone else."                                 |
|                                           -- Anonymous              |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+






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

Reply via email to