RE: [PHP] Alternating table rows...

2002-05-10 Thread David Freeman
> I've been asked if I can alternate the colors of the > rows to make the report more legible. What I usually do is something like this: if ($colour == "blue") $colour = "red" else $colour = "blue"; Then the bit where you actually output display you use $colour to set display attributes and

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 = mss

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 ar

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

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

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]

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; >

[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 =

RE: [PHP] Alternating table rows...

2002-05-10 Thread Juan Pablo Aqueveque
Just another version. the call ... $RowColor = useColor(); ... echo ''; - Jp At 15:46 10/05/02, you wrote: >[snip] >$rowcount = 0; >while($dbrowa = mysql_fetch_object($dbseta)){ > $dbrowb = mysql_fetch_object($dbsetb); >//change the color of alternating rows >$rowcount ++; >if ($row

RE: [PHP] Alternating table rows...

2002-05-10 Thread Jay Blanchard
[snip] http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

RE: [PHP] Alternating table rows...

2002-05-10 Thread Philip Olson
Yet even more ways to do it: $i = 0; while ($row = mysql_fetch_assoc($result)) { $bgcolor = ($i++ & 1) ? '#ff' : '#00'; } Or more then two: $colors = array('black','green','blue','yellow'); $i = 0; while ($row = mysql_fetch_assoc($result)) { $bgcolor = $colors[$i++ % 4]

Re: [PHP] Alternating table rows...

2002-05-10 Thread Robert Cummings
Robert Cummings wrote: > > The more generic approach: > > function getNextColour( &$lastIndex, $colourList ) > { > return $colourList[(++$lastIndex % count( $colourList ))]; U... $lastIndex++, don't want to start on the second entry :) Cheers, Rob. -- .-. | Robert Cumm

Re: [PHP] Alternating table rows...

2002-05-10 Thread Robert Cummings
The more generic approach: function getNextColour( &$lastIndex, $colourList ) { return $colourList[(++$lastIndex % count( $colourList ))]; } $colours = array ( '#ff', '#00ff00', '#ff' ); $index = 0; foreach( $rows as $aRow ) { echo '' .$aRow .''."\n";

RE: [PHP] Alternating table rows...

2002-05-10 Thread Miguel Cruz
While everyone's kicking in ideas... I don't think modulus (as someone else suggested) is that expensive, but I think this is the cheapest: $evenodd = 0; $color[0] = '#cc'; $color[1] = '#99'; while ($row = mysql_fetch_row($st)) { print "{$row['whatever']}"; $evenodd =

RE: [PHP] Alternating table rows...

2002-05-10 Thread Jay Blanchard
[snip] Is there a way for me to do one of the following: 1) Test to see if $i is an even or odd number? 2) Grab more than one line from the database at a time, and just put in two table rows at once? [/snip] \n"); } elseif ($rowcount <> 1) { print("\n");

Re: [PHP] Alternating table rows...

2002-05-10 Thread Glenn Sieb
On 02:47 AM 5/11/2002 +0800, Jason Wong wrote: > if ($i % 2) { odd; } else { even; } Great! Thanks, Jason :))) One thing I love about this list... you guys are more than helpful! :) Glenn --- Glenn E. Sieb, System Administrator Lumeta Corp. mailto:[EMAIL PROTECTED] +1 732 357-3514 (V) +

Re: [PHP] Alternating table rows...

2002-05-10 Thread Jason Wong
On Saturday 11 May 2002 02:45, Glenn Sieb wrote: > Hi everyone, > > I have a PHP script that reads data from an MS SQL server and outputs the > data into a table. I've been asked if I can alternate the colors of the > rows to make the report more legible. The relevant piece of code looks > like: >

[PHP] Alternating table rows...

2002-05-10 Thread Glenn Sieb
Hi everyone, I have a PHP script that reads data from an MS SQL server and outputs the data into a table. I've been asked if I can alternate the colors of the rows to make the report more legible. The relevant piece of code looks like: for ($i = 0; $i < mssql_num_rows( $stmt ); ++$i)