[PHP] Re: Alternating Table Rows, Part Deux..
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] : nbsp;); print (TR BGCOLOR=#$color\n\tTD$line[2]/TD\n\tTD$cname/TD\n\tTD$line[3]/TD\n/TR\n); $previous = $line[0]; } print (/TABLE); 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) Is there not a GROUP BY clause in MS SQL? I'm pretty sure there is. If you group the query by company name then you don't have to worry about duplicate company names... and it will help with performance, since the db is optimized for that and you don't have to waste PHP to determine if the row is a duplicate. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Alternating Table Rows, Part Deux..
On Fri, 10 May 2002, Austin Marshall wrote: This not only takes care of the table row colors, but also removes duplicate company names so it looks MUCH neater this way : Is there not a GROUP BY clause in MS SQL? I'm pretty sure there is. If you group the query by company name then you don't have to worry about duplicate company names... and it will help with performance, since the db is optimized for that and you don't have to waste PHP to determine if the row is a duplicate. But he's dealing with cases where the company name remains the same but other data in the row changes (for instance, a company with multiple offices, where you wanted to list the phone number and address for each). GROUP BY would discard that other data. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Alternating Table Rows, Part Deux..
Miguel Cruz wrote: On Fri, 10 May 2002, Austin Marshall wrote: This not only takes care of the table row colors, but also removes duplicate company names so it looks MUCH neater this way : Is there not a GROUP BY clause in MS SQL? I'm pretty sure there is. If you group the query by company name then you don't have to worry about duplicate company names... and it will help with performance, since the db is optimized for that and you don't have to waste PHP to determine if the row is a duplicate. But he's dealing with cases where the company name remains the same but other data in the row changes (for instance, a company with multiple offices, where you wanted to list the phone number and address for each). GROUP BY would discard that other data. miguel Yeah, apparently i wasn't the first to not catch that either. I realy should start paying attention. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Alternating Table Rows, Part Deux..
On 04:58 PM 5/10/2002 -0500, Miguel Cruz wrote: But he's dealing with cases where the company name remains the same but other data in the row changes (for instance, a company with multiple offices, where you wanted to list the phone number and address for each). GROUP BY would discard that other data. *nod* We're just doing this for ease-of-reading. Right now it'd look something along these lines: Marvin BlahBlah, Inc. 5/10/02 Notes on meeting Davis 5/10/02 More Notes on meeting etc. Glenn --- 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