Re: [PHP] Alternating Table Rows, Part Deux..

2002-05-10 Thread Glenn Sieb

On 05:11 PM 5/10/2002 -0500, Shaun Thomas wrote:
>This could use a few tweaks.

Ok I got it now... This exhibits the behaviour I was looking for, and, 
thanks to you, is much easier to read and maintain! :)))

Thanks, Shaun!
Glenn

 $sPrevCompany = $sColor = '';
 while ($aRow = mssql_fetch_row($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';
 $sPrevCompany = $sCompanyName;
 } else {
 $sCompanyName = ' ';
 }

 /* We're past our if statement, so save the previous company for
 next time. */

 print (
 "\n".
 "\t$aRow[0]\n".
 "\t$aRow[1]\n".
 "\t$sCompanyName\n".
 "\t$aRow[2]\n".
 "\t$aRow[4]\n".
 "\t$aRow[5]\n".
 "\t$aRow[6]\n".
 "\t$aRow[7]\n".
 "\n");
 }
 print ("");


---
Glenn E. Sieb, System Administrator
Lumeta Corp. mailto:[EMAIL PROTECTED]
+1 732 357-3514 (V)
+1 732 564-0731 (Fax)


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




Re: [PHP] Alternating Table Rows, Part Deux..

2002-05-10 Thread Glenn Sieb

Thanks! I'll play with this!!! :)

Glenn

On 05:11 PM 5/10/2002 -0500, Shaun Thomas wrote:
>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...):


---
Glenn E. Sieb, System Administrator
Lumeta Corp. mailto:[EMAIL PROTECTED]
+1 732 357-3514 (V)
+1 732 564-0731 (Fax)


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




Re: [PHP] Alternating Table Rows, Part Deux..

2002-05-10 Thread Shaun Thomas

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
"\n".
"\t$aRow[somecolumn]\n".
"\t$sCompanyName\n".
"\t$line[anothercolumn]\n".
"\n";
}
- CUT HERE -

And done.  Infinitely more maintainable.

-- 
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Shaun M. ThomasINN 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




Re: [PHP] Alternating Table Rows, Part Deux..

2002-05-10 Thread Robert Cummings

"1LT John W. Holmes" wrote:
> 
> Read the code again, that's what I first thought, too. He's just not
> printing multiple values for the first table cell. So if the current row has
> the same company name, just print a blank cell, then print the rest of the
> data for that row.

In the words of a great man: "Doh!"

Cheers,
Rob.
-- 
.-.
| Robert Cummings |
:-`.
| Webdeployer - Chief PHP and Java Programmer  |
:--:
| Mail  : mailto:[EMAIL PROTECTED] |
| Phone : (613) 731-4046 x.109 |
:--:
| Website : http://www.webmotion.com   |
| Fax : (613) 260-9545 |
`--'

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




Re: [PHP] Alternating Table Rows, Part Deux..

2002-05-10 Thread 1LT John W. Holmes

- Original Message -
From: "Robert Cummings" <[EMAIL PROTECTED]>
> Glenn Sieb wrote:
> >   $cname =
(strcmp($previous,$line[0])
> > ? $line[0] : " ");
> >   print (" >
BGCOLOR=#$color>\n\t$line[2]\n\t$cname\n\t$line[3]\n\n");
> >   $previous = $line[0];
> >   }
> >  print ("");
> >
> > This not only takes care of the table row colors, but also removes
> > duplicate company names so it looks MUCH neater this way :
>
> YIKES! I thought there was a SQL keyword for returning a unique
> rowset.

Read the code again, that's what I first thought, too. He's just not
printing multiple values for the first table cell. So if the current row has
the same company name, just print a blank cell, then print the rest of the
data for that row.

---John Holmes...


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




Re: [PHP] Alternating Table Rows, Part Deux..

2002-05-10 Thread Robert Cummings

Glenn Sieb wrote:
> 
> Hey everyone!
> 
> Thanks for all the hints--here's what my boss and I eventually came out with:
> 
> /*  ##
>  ## And for every row of data we pull, we create a table row...
>  ## */
>  $company = 0;
>  $previous = "";
>  for ($i = 0; $i < mssql_num_rows( $stmt ); ++$i)
>   {
>   $line = mssql_fetch_row($stmt);
>   $company +=
> (strcmp($previous,$line[0]) ? 1 : 0);
>   $color = (($company%2) ? "FF" :
> "00");
>   $cname = (strcmp($previous,$line[0])
> ? $line[0] : " ");
>   print (" 
>BGCOLOR=#$color>\n\t$line[2]\n\t$cname\n\t$line[3]\n\n");
>   $previous = $line[0];
>   }
>  print ("");
> 
> This not only takes care of the table row colors, but also removes
> duplicate company names so it looks MUCH neater this way :

YIKES! I thought there was a SQL keyword for returning a unique
rowset.

Cheers,
Rob.
-- 
.-.
| Robert Cummings |
:-`.
| Webdeployer - Chief PHP and Java Programmer  |
:--:
| Mail  : mailto:[EMAIL PROTECTED] |
| Phone : (613) 731-4046 x.109 |
:--:
| Website : http://www.webmotion.com   |
| Fax : (613) 260-9545 |
`--'

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




[PHP] Alternating Table Rows, Part Deux..

2002-05-10 Thread Glenn Sieb

Hey everyone!

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

/*  ##
 ## And for every row of data we pull, we create a table row...
 ## */
 $company = 0;
 $previous = "";
 for ($i = 0; $i < mssql_num_rows( $stmt ); ++$i)
  {
  $line = mssql_fetch_row($stmt);
  $company += 
(strcmp($previous,$line[0]) ? 1 : 0);
  $color = (($company%2) ? "FF" : 
"00");
  $cname = (strcmp($previous,$line[0]) 
? $line[0] : " ");
  print ("\n\t$line[2]\n\t$cname\n\t$line[3]\n\n");
  $previous = $line[0];
  }
 print ("");

This not only takes care of the table row colors, but also removes 
duplicate company names so it looks MUCH neater this way :

Thanks again!
Glenn
(who's still trying to get it all down lol.. between trying to learn SQL, 
MySQL,PHP, PostgreSQL, and VBScript lately, I'm surprised I haven't had my 
head explode yet!)

---
Glenn E. Sieb, System Administrator
Lumeta Corp. mailto:[EMAIL PROTECTED]
+1 732 357-3514 (V)
+1 732 564-0731 (Fax)


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