On Tue, Aug 11, 2009 at 10:09 AM, tedd <tedd.sperl...@gmail.com> wrote:
> At 8:46 AM -0400 8/11/09, tedd wrote: > >> At 4:16 PM -0600 8/10/09, John Butler wrote: >> >>> quick Q: >>> I have this inside a foreach{} that I want to alternate between on and >>> off so I can alternate the background-color of my <tr>'s. >>> >>> $tableRowBGcolorBoolCounter != $tableRowBGcolorBoolCounter; //-boolean on >>> and off >>> >>> I am looking thru' docs and books, but can't remember (nor find now) in >>> PHP how to say "inverse your value" (to a boolean). >>> ? >>> >>> TIA! -G >>> >> >> John: >> >> Here's my solution: >> >> http://webbytedd.com/b/color-rows/ >> >> Cheers, >> >> tedd >> > > However, my solution (after reading others) is for an alternating row color > (a boolean operation). > > The problem was NOT making every third row a different color or making > every row a different color. Those problems would require different > solutions. > > There is nothing wrong with embedding php within html, which is really a > misnomer because it's the php interpreter that's sending the resultant html > to the browser. It is not sending php snip-its for the browser to handle. > So, embedding code such as: > > <tr class="row<?php echo($i++ & 1);?>"> > > Is a valid statement that works. It would be nice if you initialize the $i > value, but it will work either way. > > My solution, provided via the above link, is a valid solution. > > > Cheers, > > tedd > > -- > ------- > http://sperling.com http://ancientstones.com http://earthstones.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > A change request just came in - the interaction designer wants every third line to have a grey background, instead of every second line. # before was $styles = array( 'even', 'odd' ); # after new requirements it is... $styles = array( 'white', 'white', 'gray' ); foreach($items as $item) { printf( '<li class="%s">%s</li>', current( $styles ), $item ); next( $styles ) or reset( $styles ); } The simplest solution is always the best choice. This provides maintainability and flexibility to changes ( that we don't know yet ) -- Martin Scotta