Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-12 Thread Jim Lucas
 way to do
 it.
 

I have found, in a number of cases, that using only the TR  tag
doesn't work all the time.

 }

 No need to initialize $dr as by default PHP will make it a 
 boolean false,
 then each itteration, it will toggle true/false and 
 substitute the CSS class
 -Original Message-
 From: Jim Lucas [mailto:li...@cmsws.com] 
 Sent: Monday, August 10, 2009 4:03 PM
 To: John Butler
 Cc: PHP-General List
 Subject: Re: [PHP] how to say inverse your value (to a boolean)?

 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


 ?php

 $arr = range(1, 10);

 $i = 0;
 foreach ( $arr AS $row ) {

$row_color = ( ( $i++ % 2 ) ? 'green' : 'red');

echo $row_color;

 }

 ?

 another (neat|strange)+ way I use the above is like so

 style
  .rowColor0 { background: #FF; }
  .rowColor1,
  .rowColor3 { background: #EE; }
  .rowColor2 { background: #DD; }
 /style
 ?php

 $arr = range(1, 10);

 $i = 0;

 foreach ( $arr AS $row ) {

  echo 'trtd class=rowColor'.( $i++ % 4 
 ).'''.$row.'/td/tr';

 }
 ?

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



 -- 
 Jim Lucas

 Some men are born to greatness, some achieve greatness,
 and some have greatness thrust upon them.

 Twelfth Night, Act II, Scene V
  by William Shakespeare

 
 



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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-12 Thread tedd

At 8:33 AM -0700 8/12/09, Jim Lucas wrote:

Daevid Vincent wrote:



-snip-

I side with Jim on this. I never use short tags and write similar crap.

Jim said:


I have found, in a number of cases, that using only the TR  tag
doesn't work all the time.


It should work ALL the time, but sometimes inheritance overrides what 
you think is happening. In such cases, try adding !important to the 
rule and I think you'll see what you expect.


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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-12 Thread Ralph Deffke
thats why I decided years ago to write myself a little bunch of classes for
the html tags which gives me the ability to have PHP only code, very nice,
no errors and my outputs dont even need Tidy pure XHTML

i find these idear of mixing html and php as spagetty, using divs for tables
as something what facirs do,

no problems with unexpected header outputs, no small fat grafic designer can
make my live difficult, I can change evrything on the fly.

pure OOP

one final echo $page-toHtml();

put a candle for the invention of OOP ...
better as sex
makes the nights fun

consider this guys

ralph_def...@yahoo.de


tedd tedd.sperl...@gmail.com wrote in message
news:p06240800c6a892b12...@[192.168.1.100]...
 At 8:33 AM -0700 8/12/09, Jim Lucas wrote:
 Daevid Vincent wrote:


 -snip-

 I side with Jim on this. I never use short tags and write similar crap.

 Jim said:

 I have found, in a number of cases, that using only the TR  tag
 doesn't work all the time.

 It should work ALL the time, but sometimes inheritance overrides what
 you think is happening. In such cases, try adding !important to the
 rule and I think you'll see what you expect.

 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



RE: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Ford, Mike
 -Original Message-
 From: Daevid Vincent [mailto:dae...@daevid.com]
 Sent: 11 August 2009 02:19
 
 Then YOU have more aggressive error_reporting than the default
 setting
 turned on. You might consider turning it down a notch. NOTICEs are
 basically
 useless and bloat your code IMHO -- and apparently the PHP devs too
 as per
 this...
 
 http://us2.php.net/manual/en/function.error-reporting.php
 
 // Report all errors except E_NOTICE
 // This is the default value set in php.ini
 error_reporting(E_ALL ^ E_NOTICE);

Yes, but recent versions also have the following recommended settings:

; error_reporting
;   Development Value: E_ALL | E_STRICT
;   Production Value: E_ALL  ~E_DEPRECATED

; display_errors
;   Development Value: On
;   Production Value: Off


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730






To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread David Otton
2009/8/11 Daevid Vincent dae...@daevid.com:

 NO! For the love of God and all that is holy, don't do that accumulator /
 mod hack.
 That's so 1980's. And why make the CPU do all that math for every row...

 Just do this. It's quick and simple:

 CSS:
        .dataRow1 { background-color: #DFDFDF; }
        .dataRow2 { background-color: #FF; }

 foreach ($foo_array as $foo) {
   ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo
 ?/td/tr?php
 }

A change request just came in - the interaction designer wants every
third line to have a grey background, instead of every second line.

 No need to initialize $dr as by default PHP will make it a boolean false,
 then each itteration, it will toggle true/false and substitute the CSS class

Um. No. Just no.

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Ashley Sheridan
On Tue, 2009-08-11 at 11:28 +0100, David Otton wrote:
 2009/8/11 Daevid Vincent dae...@daevid.com:
 
  NO! For the love of God and all that is holy, don't do that accumulator /
  mod hack.
  That's so 1980's. And why make the CPU do all that math for every row...
 
  Just do this. It's quick and simple:
 
  CSS:
 .dataRow1 { background-color: #DFDFDF; }
 .dataRow2 { background-color: #FF; }
 
  foreach ($foo_array as $foo) {
?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo
  ?/td/tr?php
  }
 
 A change request just came in - the interaction designer wants every
 third line to have a grey background, instead of every second line.
 
  No need to initialize $dr as by default PHP will make it a boolean false,
  then each itteration, it will toggle true/false and substitute the CSS class
 
 Um. No. Just no.
 
I tend to do something like this:

$count = 0;
foreach($foo_array as $foo)
{
$class = ($count % 3 == 0)?'class=thirdRow':'';
print tr $classtd$foo/td/tr;
}

You only need to give one row the class, as you style up all the rows
and only change the row that needs to change.

Thanks,
Ash
http://www.ashleysheridan.co.uk


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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Ralph Deffke
seems they changing idears on the fly? could it be that the designer is a
smal ugly person while u a a good looking ladykiller ?

on that background I would design a function where u can change ti what ever
u want on the fly something like this

var $a;
function alternate(  $a, $_b=array( red, red ,green ,... ) {
if( count( $_b )  $a ) {
return $_b[ $a++ ] ;
}
$a=0;
return $_b[ $a++ ] ;
}

so now u can do what ever anybody wants on just putting the right values
into the array

cheers

ralph
ralph_def...@yahoo.de

David Otton phpm...@jawbone.freeserve.co.uk wrote in message
news:193d27170908110328p43b4722fkc46b0bcda97fc...@mail.gmail.com...
2009/8/11 Daevid Vincent dae...@daevid.com:

 NO! For the love of God and all that is holy, don't do that accumulator /
 mod hack.
 That's so 1980's. And why make the CPU do all that math for every
row...

 Just do this. It's quick and simple:

 CSS:
 .dataRow1 { background-color: #DFDFDF; }
 .dataRow2 { background-color: #FF; }

 foreach ($foo_array as $foo) {
 ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo
 ?/td/tr?php
 }

A change request just came in - the interaction designer wants every
third line to have a grey background, instead of every second line.

 No need to initialize $dr as by default PHP will make it a boolean
false,
 then each itteration, it will toggle true/false and substitute the CSS
class

Um. No. Just no.



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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread tedd

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

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread tedd

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Martin Scotta
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


Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Conor Mac Aoidh

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


If I was going to do that then I would use jQuery:

script type=text/javascript
$(document).ready(function(){
$(table tr:even).addClass(even);;
$(table tr:odd).addClass(odd);;
});
/script

And yes I know that this is a PHP mailing list lol

--
Conor

http://conormacaoidh.com

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread tedd

At 2:29 PM +0100 8/11/09, Conor Mac Aoidh 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


If I was going to do that then I would use jQuery:

script type=text/javascript
$(document).ready(function(){
$(table tr:even).addClass(even);;
$(table tr:odd).addClass(odd);;
});
/script

And yes I know that this is a PHP mailing list lol

--
Conor



And if javascript is turned off?

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread tedd

At 10:27 AM -0300 8/11/09, Martin Scotta wrote:

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


The simplest solution is in the eyes of the beholder.

My solution was the simplest for the problem presented.

You presented a different problem with a different 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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Ben Dunlap
 # 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 );
 }


+5000. I think is by far the most readable and flexible solution suggested.
I also like it because it's PHPish -- it uses the features of the language
that were made-to-order for this problem.

Ben


Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Robert Cummings

Ben Dunlap wrote:

# 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 );
}



+5000. I think is by far the most readable and flexible solution suggested.
I also like it because it's PHPish -- it uses the features of the language
that were made-to-order for this problem.


Actually it's the wrong way to do it.

Change the class names to alternate1 and alternate2 (or something 
else meaningful without being tied to a definition). That way when you 
set the colour for style white to green it doesn't result in 
confusion. Seriously though... this is nomenclature 101.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Ben Dunlap
 # 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 );
 }


  +5000. I think is by far the most readable and flexible solution
 suggested.
 I also like it because it's PHPish -- it uses the features of the language
 that were made-to-order for this problem.


 Actually it's the wrong way to do it.

 Change the class names to alternate1 and alternate2 (or something else
 meaningful without being tied to a definition). That way when you set the
 colour for style white to green it doesn't result in confusion.
 Seriously though... this is nomenclature 101.


Good point, and thanks for the presentation-vs-content reality check. I'll
downgrade my vote to a more sober +4990, in consideration of the class names
in $styles.

Ben


Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread John Butler

What a lot of good ideas spawned from the OP!
I am learning many things,.. while also actually working (paying  
bills), so I regularly have to just go with what I know well.


Anyway, I already have the forearch { loop (for other reasons it is  
necessary), and I only needed one color to alternate with the default  
white..  so I used this:


 forearch { ...
$tableRowBGcolorBoolCounter = !$tableRowBGcolorBoolCounter; //-boolean  
on and off


(which then sticks in one CSS class or another for that tr.

thanks for everyone's feedback.
-John

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread tedd

At 1:53 PM -0600 8/11/09, John Butler wrote:

What a lot of good ideas spawned from the OP!
I am learning many things,.. while also actually working (paying 
bills), so I regularly have to just go with what I know well.


Anyway, I already have the forearch { loop (for other reasons it is 
necessary), and I only needed one color to alternate with the 
default white..  so I used this:


 forearch { ...
$tableRowBGcolorBoolCounter = !$tableRowBGcolorBoolCounter; 
//-boolean on and off


(which then sticks in one CSS class or another for that tr.

thanks for everyone's feedback.
-John


Yeah, but forearch ain't going to work.

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread John Butler

What a lot of good ideas spawned from the OP!
I am learning many things,.. while also actually working (paying  
bills), so I regularly have to just go with what I know well.


Anyway, I already have the forearch { loop (for other reasons it is  
necessary), and I only needed one color to alternate with the  
default white..  so I used this:


forearch { ...
$tableRowBGcolorBoolCounter = !$tableRowBGcolorBoolCounter; //- 
boolean on and off


(which then sticks in one CSS class or another for that tr.

thanks for everyone's feedback.
-John


Yeah, but forearch ain't going to work.



what do you mean?  I must have neglected to include more of the  
relevant code to show you that it IS working just fine.   I will  
certainly explain more if you ask..  but the whole point of me  
starting the thread was just to be reminded how to inverse a boolean  
var's value.  Tony answered me; I am happy.   I assume you don't want  
me (the newbie) to show how I have it working. (?)



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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Robert Cummings

John Butler wrote:

What a lot of good ideas spawned from the OP!
I am learning many things,.. while also actually working (paying  
bills), so I regularly have to just go with what I know well.


Anyway, I already have the forearch { loop (for other reasons it is  
necessary), and I only needed one color to alternate with the  
default white..  so I used this:


forearch { ...
$tableRowBGcolorBoolCounter = !$tableRowBGcolorBoolCounter; //- 
boolean on and off


(which then sticks in one CSS class or another for that tr.

thanks for everyone's feedback.
-John

Yeah, but forearch ain't going to work.



what do you mean?  I must have neglected to include more of the  
relevant code to show you that it IS working just fine.   I will  
certainly explain more if you ask..  but the whole point of me  
starting the thread was just to be reminded how to inverse a boolean  
var's value.  Tony answered me; I am happy.   I assume you don't want  
me (the newbie) to show how I have it working. (?)


He's pointing out a typo... forearch instead of foreach :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread John Butler

He's pointing out a typo... forearch instead of foreach :)


LOL!

I almost always miss the jokes.

Thanks for the smiley face to get my (lighter) attention ;-)

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



RE: [PHP] how to say inverse your value (to a boolean)?

2009-08-11 Thread Daevid Vincent
 

 -Original Message-
 Daevid Vincent wrote:
  NO! For the love of God and all that is holy, don't do that 
 accumulator / mod hack. 
  That's so 1980's. And why make the CPU do all that math 
 for every row...
  
  Just do this. It's quick and simple:
  
  CSS:
  .dataRow1 { background-color: #DFDFDF; }
  .dataRow2 { background-color: #FF; }
  
  foreach ($foo_array as $foo) {
 ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 
 ?td?= $foo
  ?/td/tr?php
 
 Wow, were to start with all the problems in the above code:
 1.  Short tags?

Nothing wrong with them. Do yourself a test. There is zero speed difference
in a page. It makes your code cleaner and easier to read, plus less
kilobytes you have to pull from the hard drive, therefore faster pages.

http://stackoverflow.com/questions/662891/is-there-a-speed-difference-betwee
n-php-echo-var-and-var

http://cubicspot.blogspot.com/2009/06/maximum-failure-php-6-deprecates-short
.html

Are you sure you're not confused with short_open_tags ie. ? ? -- which I
am fully against (as am I against % % too), although sadly they are lumped
into the same directive, when IMHO they should be separate.

http://us.php.net/manual/en/ini.core.php#ini.short-open-tag

http://www.php.net/~derick/meeting-notes.html#remove-support-for-and-script-
language-php-and-add-php-var

 2.  Not using echo or print.  

?= ? is a fantastic shortcut to the antiquated ?php echo ; ? B.S.
The vast majority of your page is output in little fragments like this, so
why not keep it clean and easy to read. Why would you purposely choose to be
more verbose than you need to be for something as basic as print.

 You actually recommend breaking in/out of php?

Hell yeah I do. THAT is one of the MAIN reasons to use PHP. Otherwise, why
not just render your whole page with a bunch of $html .= 'trtd...';
tags and print $html at the end. Welcome to the year 2000 my friend.

You're probably the same kind of person that does this crap:

if ($foo == true)
{
   echo A;
}
else
{
   echo B;
}

(complete with extra braces and checking for 'true' explicitly, but not
using === in such cases)

Rather than a much cleaner, easier to read/write and more concise:

 ?= ($foo) ? 'A' : 'B' ?


 3.  Using uninitialized variables (I run with the E_ALL crowd)

I'm so happy for you. Do you have a membership card and everything? That's
your own masochistic fault then. I run with the
save-myself-the-headache-and-write-clean-efficient-code crowd.

 4.  Using the tr class='' and not the td class=''...  Hmmm

Maybe you're new to how HTML works, but if you want to highlight a ROW (as
the OP did), then you put the background color on the highest parent that it
applies to. Hey imagine that, there is a TR tag which stands for TABLE ROW
tag. Seems obvious to me. This reduces your page size in kilobytes, makes a
much cleaner HTML rendering to read in source, and is the PROPER way to do
it.

  }
  
  No need to initialize $dr as by default PHP will make it a 
 boolean false,
  then each itteration, it will toggle true/false and 
 substitute the CSS class
  
  -Original Message-
  From: Jim Lucas [mailto:li...@cmsws.com] 
  Sent: Monday, August 10, 2009 4:03 PM
  To: John Butler
  Cc: PHP-General List
  Subject: Re: [PHP] how to say inverse your value (to a boolean)?
 
  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
 
 
  ?php
 
  $arr = range(1, 10);
 
  $i = 0;
  foreach ( $arr AS $row ) {
 
 $row_color = ( ( $i++ % 2 ) ? 'green' : 'red');
 
 echo $row_color;
 
  }
 
  ?
 
 
 another (neat|strange)+ way I use the above is like so
 
 style
   .rowColor0 { background: #FF; }
   .rowColor1,
   .rowColor3 { background: #EE; }
   .rowColor2 { background: #DD; }
 /style
 ?php
 
 $arr = range(1, 10);
 
 $i = 0;
 
 foreach ( $arr AS $row ) {
 
   echo 'trtd class=rowColor'.( $i++ % 4 
 ).'''.$row.'/td/tr';
 
 }
 ?
 
 
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
  
  
 
 
 -- 
 Jim Lucas
 
 Some men are born to greatness, some achieve greatness,
 and some have greatness thrust upon them.
 
 Twelfth Night, Act II, Scene V
  by William Shakespeare
 


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



[PHP] how to say inverse your value (to a boolean)?

2009-08-10 Thread John Butler

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


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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-10 Thread Martin Scotta
You can do this...

for( $b=true; your-statement; $b = !$b )
{
your-code
}

I usually use this solution

$types = array( 'one', 'two' );
foreach( $list as $item ) # -- your set of (many) items
{
echo current( $types ); # -- this prints the current class
# code
next( $types ) or reset( $types ); # and this do the magic
}

Hey! look, this solution can work with more than 2 types...
try it with many types: $types = array( 'one', 'two', three', 'four' );

On Mon, Aug 10, 2009 at 7:16 PM, John Butler
govinda.webdnat...@gmail.comwrote:

 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


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




-- 
Martin Scotta


RE: [PHP] how to say inverse your value (to a boolean)?

2009-08-10 Thread Daevid Vincent
NO! For the love of God and all that is holy, don't do that accumulator /
mod hack. 
That's so 1980's. And why make the CPU do all that math for every row...

Just do this. It's quick and simple:

CSS:
.dataRow1 { background-color: #DFDFDF; }
.dataRow2 { background-color: #FF; }

foreach ($foo_array as $foo) {
   ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo
?/td/tr?php
}

No need to initialize $dr as by default PHP will make it a boolean false,
then each itteration, it will toggle true/false and substitute the CSS class

 -Original Message-
 From: Jim Lucas [mailto:li...@cmsws.com] 
 Sent: Monday, August 10, 2009 4:03 PM
 To: John Butler
 Cc: PHP-General List
 Subject: Re: [PHP] how to say inverse your value (to a boolean)?
 
 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
  
  
 
 ?php
 
 $arr = range(1, 10);
 
 $i = 0;
 foreach ( $arr AS $row ) {
 
   $row_color = ( ( $i++ % 2 ) ? 'green' : 'red');
 
   echo $row_color;
 
 }
 
 ?
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-10 Thread Martin Scotta
Use...

$dr = !$dr

if you want

Notice: Undefined variable: dr

All variables MUST be initialized before using.
If you PHP does not complains about it you should read about error_reporting

On Mon, Aug 10, 2009 at 8:18 PM, Daevid Vincent dae...@daevid.com wrote:

 NO! For the love of God and all that is holy, don't do that accumulator /
 mod hack.
 That's so 1980's. And why make the CPU do all that math for every
 row...

 Just do this. It's quick and simple:

 CSS:
.dataRow1 { background-color: #DFDFDF; }
.dataRow2 { background-color: #FF; }

 foreach ($foo_array as $foo) {
   ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo
 ?/td/tr?php
 }

 No need to initialize $dr as by default PHP will make it a boolean false,
 then each itteration, it will toggle true/false and substitute the CSS
 class

  -Original Message-
  From: Jim Lucas [mailto:li...@cmsws.com]
  Sent: Monday, August 10, 2009 4:03 PM
  To: John Butler
  Cc: PHP-General List
  Subject: Re: [PHP] how to say inverse your value (to a boolean)?
 
  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
  
  
 
  ?php
 
  $arr = range(1, 10);
 
  $i = 0;
  foreach ( $arr AS $row ) {
 
$row_color = ( ( $i++ % 2 ) ? 'green' : 'red');
 
echo $row_color;
 
  }
 
  ?
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 


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




-- 
Martin Scotta


RE: [PHP] how to say inverse your value (to a boolean)?

2009-08-10 Thread Daevid Vincent
Then YOU have more aggressive error_reporting than the default setting
turned on. You might consider turning it down a notch. NOTICEs are basically
useless and bloat your code IMHO -- and apparently the PHP devs too as per
this...

http://us2.php.net/manual/en/function.error-reporting.php

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

Don't tell me what to do! You're not my father! ;-)

http://daevid.com

Some people, when confronted with a problem, think 'I know, I'll use XML.'
Now they have two problems. 

 -Original Message-
 From: Martin Scotta [mailto:martinsco...@gmail.com] 
 Sent: Monday, August 10, 2009 5:39 PM
 To: Daevid Vincent
 Cc: PHP-General List
 Subject: Re: [PHP] how to say inverse your value (to a boolean)?
 
 Use...
 
 $dr = !$dr
 
 if you want
 
 Notice: Undefined variable: dr
 
 All variables MUST be initialized before using.
 If you PHP does not complains about it you should read about 
 error_reporting
 
 On Mon, Aug 10, 2009 at 8:18 PM, Daevid Vincent 
 dae...@daevid.com wrote:
 
  NO! For the love of God and all that is holy, don't do that 
 accumulator /
  mod hack.
  That's so 1980's. And why make the CPU do all that math 
 for every
  row...
 
  Just do this. It's quick and simple:
 
  CSS:
 .dataRow1 { background-color: #DFDFDF; }
 .dataRow2 { background-color: #FF; }
 
  foreach ($foo_array as $foo) {
?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 
 ?td?= $foo
  ?/td/tr?php
  }
 
  No need to initialize $dr as by default PHP will make it a 
 boolean false,
  then each itteration, it will toggle true/false and 
 substitute the CSS
  class
 
   -Original Message-
   From: Jim Lucas [mailto:li...@cmsws.com]
   Sent: Monday, August 10, 2009 4:03 PM
   To: John Butler
   Cc: PHP-General List
   Subject: Re: [PHP] how to say inverse your value (to a boolean)?
  
   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
   
   
  
   ?php
  
   $arr = range(1, 10);
  
   $i = 0;
   foreach ( $arr AS $row ) {
  
 $row_color = ( ( $i++ % 2 ) ? 'green' : 'red');
  
 echo $row_color;
  
   }
  
   ?
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 -- 
 Martin Scotta
 


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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-10 Thread Paul M Foster
On Mon, Aug 10, 2009 at 04:18:29PM -0700, Daevid Vincent wrote:

 NO! For the love of God and all that is holy, don't do that accumulator /
 mod hack.
 That's so 1980's. And why make the CPU do all that math for every row...
 
 Just do this. It's quick and simple:
 
 CSS:
   .dataRow1 { background-color: #DFDFDF; }
   .dataRow2 { background-color: #FF; }
 
 foreach ($foo_array as $foo) {
?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo
 ?/td/tr?php
 }


NO! For the love of God and all that is holy, don't do that ?= hack.
That's so 1990's.

Just do this. It's quick and simple:

tr class=?php echo ($dr = !$dr) ? dataRow1 : dataRow2 ?

(I just couldn't resist! ;-)

Paul

-- 
Paul M. Foster

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



Re: [PHP] how to say inverse your value (to a boolean)?

2009-08-10 Thread Jim Lucas

Daevid Vincent wrote:

NO! For the love of God and all that is holy, don't do that accumulator /
mod hack. 
That's so 1980's. And why make the CPU do all that math for every row...


Just do this. It's quick and simple:

CSS:
.dataRow1 { background-color: #DFDFDF; }
.dataRow2 { background-color: #FF; }

foreach ($foo_array as $foo) {
   ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo
?/td/tr?php


Wow, were to start with all the problems in the above code:
1.  Short tags?
2.  Not using echo or print.  You actually recommend breaking in/out of php?
3.  Using uninitialized variables (I run with the E_ALL crowd)
4.  Using the tr class='' and not the td class=''...  Hmmm


}

No need to initialize $dr as by default PHP will make it a boolean false,
then each itteration, it will toggle true/false and substitute the CSS class


-Original Message-
From: Jim Lucas [mailto:li...@cmsws.com] 
Sent: Monday, August 10, 2009 4:03 PM

To: John Butler
Cc: PHP-General List
Subject: Re: [PHP] how to say inverse your value (to a boolean)?

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



?php

$arr = range(1, 10);

$i = 0;
foreach ( $arr AS $row ) {

$row_color = ( ( $i++ % 2 ) ? 'green' : 'red');

echo $row_color;

}

?



another (neat|strange)+ way I use the above is like so

style
.rowColor0 { background: #FF; }
.rowColor1,
.rowColor3 { background: #EE; }
.rowColor2 { background: #DD; }
/style
?php

$arr = range(1, 10);

$i = 0;

foreach ( $arr AS $row ) {

echo 'trtd class=rowColor'.( $i++ % 4 ).'''.$row.'/td/tr';

}
?



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







--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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