ternary operator sintax help

ternary operator sintax help

am 06.10.2009 20:43:41 von talofo talofo

Hello all,

I'm trying to display a div, only when some php value is set.
Since this will be near html, I'd like to keep it on one line. So, I'd =
love
to use shortcuts and a ternary operator for the effect.

I'm having something like this right now, but the div still appears even =
if
the error is NOT set.

'
..$erros['anexo'].'' :''; ?>

:(=20

Can I have your help with the right syntax ?


Regards,
The newbie on a Humpty Dumpty wall,
M=E1rcio


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

Re: ternary operator sintax help

am 06.10.2009 20:48:31 von Ashley Sheridan

--=-RrsuIr3iBAlgYiGIJEEF
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Tue, 2009-10-06 at 19:43 +0100, MEM wrote:

> Hello all,
>=20
> I'm trying to display a div, only when some php value is set.
> Since this will be near html, I'd like to keep it on one line. So, I'd lo=
ve
> to use shortcuts and a ternary operator for the effect.
>=20
> I'm having something like this right now, but the div still appears even =
if
> the error is NOT set.
>=20
> '
> .$erros['anexo'].'' :''; ?>
>=20
> :(=20
>=20
> Can I have your help with the right syntax ?
>=20
>=20
> Regards,
> The newbie on a Humpty Dumpty wall,
> Márcio
>=20
>=20


Firstly, short tags being on, which causes all sorts of problems should you ever
need PHP to output XML.

The only reason I can see that the div will always appear is a logic
error. Are you sure that the $erros['anexo'] variable is not set at some
point and not just set to an empty string? An empty string is very
different from an unset variable. Try using var_dump($erros['anexo']);
in your code somewhere to see if the it is actually an empty string
instead.

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



--=-RrsuIr3iBAlgYiGIJEEF--

Re: ternary operator sintax help

am 06.10.2009 20:52:56 von joao

class="mensagemErro">'.$erros['anexo'].'' :''); ?>

""MEM"" escreveu na mensagem
news:002401ca46b4$ed6ad6a0$c84083e0$@com...
Hello all,

I'm trying to display a div, only when some php value is set.
Since this will be near html, I'd like to keep it on one line. So, I'd love
to use shortcuts and a ternary operator for the effect.

I'm having something like this right now, but the div still appears even if
the error is NOT set.

'
..$erros['anexo'].'' :''; ?>

:(

Can I have your help with the right syntax ?


Regards,
The newbie on a Humpty Dumpty wall,
Márcio



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

RE: ternary operator sintax help

am 06.10.2009 21:04:48 von talofo talofo

------=_NextPart_000_0038_01CA46C0.428CA860
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Thanks. I will give up on =20
I have declared the erros variable like this:
=20
$erros=3Darray();
=20
Instead of isset Iâ€=99ve also tried with empty();
=20
If I have something like this, it works:
=20

$erros['anexo'] : ''; ?>

=20
I mean, it will show the message only when the form gets submitted. At =
the beginning it will have ‘’.=20
=20
:s
=20
Regards,
Marcio
=20
=20
=20
From: Ashley Sheridan [mailto:ash@ashleysheridan.co.uk]=20
Sent: terça-feira, 6 de Outubro de 2009 19:49
To: MEM
Cc: php-general@lists.php.net
Subject: Re: [PHP] ternary operator sintax help
=20
On Tue, 2009-10-06 at 19:43 +0100, MEM wrote:=20
=20
Hello all,
=20
I'm trying to display a div, only when some php value is set.
Since this will be near html, I'd like to keep it on one line. So, I'd =
love
to use shortcuts and a ternary operator for the effect.
=20
I'm having something like this right now, but the div still appears even =
if
the error is NOT set.
=20
'
..$erros['anexo'].'' :''; ?>
=20
:(=20
=20
Can I have your help with the right syntax ?
=20
=20
Regards,
The newbie on a Humpty Dumpty wall,
Márcio
=20
=20

Firstly, short tags being on, which causes all sorts of problems should you ever =
need PHP to output XML.

The only reason I can see that the div will always appear is a logic =
error. Are you sure that the $erros['anexo'] variable is not set at some =
point and not just set to an empty string? An empty string is very =
different from an unset variable. Try using var_dump($erros['anexo']); =
in your code somewhere to see if the it is actually an empty string =
instead.

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


=20

------=_NextPart_000_0038_01CA46C0.428CA860--

RE: Re: ternary operator sintax help

am 06.10.2009 21:26:27 von talofo talofo

Sorry all,
It's ok. The sintax:

class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>

Was right all the time.=20

Anyway, I've learn something new: having a var with '' is not the same =
thing
as not been unset. So we must pay attention on what cases we use isset, =
or
!empty.


Thanks a lot,
M=E1rcio

> -----Original Message-----
> From: Jo=E3o C=E2ndido de Souza Neto [mailto:joao@consultorweb.cnt.br]
> Sent: ter=E7a-feira, 6 de Outubro de 2009 19:53
> To: php-general@lists.php.net
> Subject: [PHP] Re: ternary operator sintax help
>=20
> > class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>
>=20
> ""MEM"" escreveu na mensagem
> news:002401ca46b4$ed6ad6a0$c84083e0$@com...
> Hello all,
>=20
> I'm trying to display a div, only when some php value is set.
> Since this will be near html, I'd like to keep it on one line. So, I'd
> love
> to use shortcuts and a ternary operator for the effect.
>=20
> I'm having something like this right now, but the div still appears
> even if
> the error is NOT set.
>=20
> '
> .$erros['anexo'].'' :''; ?>
>=20
> :(
>=20
> Can I have your help with the right syntax ?
>=20
>=20
> Regards,
> The newbie on a Humpty Dumpty wall,
> M=E1rcio
>=20
>=20
>=20
> --
> 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: Re: ternary operator sintax help

am 06.10.2009 22:09:10 von Philip Thompson

On Oct 6, 2009, at 2:26 PM, MEM wrote:

> Sorry all,
> It's ok. The sintax:
>
> > class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>
>
> Was right all the time.
>
> Anyway, I've learn something new: having a var with '' is not the =20
> same thing
> as not been unset. So we must pay attention on what cases we use =20
> isset, or
> !empty.
>
>
> Thanks a lot,
> M=E1rcio
>
>> -----Original Message-----
>> From: Jo=E3o C=E2ndido de Souza Neto =
[mailto:joao@consultorweb.cnt.br]
>> Sent: ter=E7a-feira, 6 de Outubro de 2009 19:53
>> To: php-general@lists.php.net
>> Subject: [PHP] Re: ternary operator sintax help
>>
>> >> class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>
>>
>> ""MEM"" escreveu na mensagem
>> news:002401ca46b4$ed6ad6a0$c84083e0$@com...
>> Hello all,
>>
>> I'm trying to display a div, only when some php value is set.
>> Since this will be near html, I'd like to keep it on one line. So, =20=

>> I'd
>> love
>> to use shortcuts and a ternary operator for the effect.
>>
>> I'm having something like this right now, but the div still appears
>> even if
>> the error is NOT set.
>>
>> '
>> .$erros['anexo'].'' :''; ?>
>>
>> :(
>>
>> Can I have your help with the right syntax ?

Another one to consider...

strlen ($item) > 0 ? 'not empty' : 'empty';

Because "empty()" will return true if 0 is the value, sometimes you =20
have to check for the length of the item.

~Philip


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

Re: Re: ternary operator sintax help

am 06.10.2009 22:10:26 von Tom Worster

just as ashley said it.


On 10/6/09 3:26 PM, "MEM" wrote:

> Sorry all,
> It's ok. The sintax:
>=20
> > class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>
>=20
> Was right all the time.
>=20
> Anyway, I've learn something new: having a var with '' is not the same th=
ing
> as not been unset. So we must pay attention on what cases we use isset, o=
r
> !empty.
>=20
>=20
> Thanks a lot,
> M=E1rcio
>=20
>> -----Original Message-----
>> From: Jo=E3o C=E2ndido de Souza Neto [mailto:joao@consultorweb.cnt.br]
>> Sent: ter=E7a-feira, 6 de Outubro de 2009 19:53
>> To: php-general@lists.php.net
>> Subject: [PHP] Re: ternary operator sintax help
>>=20
>> >> class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>
>>=20
>> ""MEM"" escreveu na mensagem
>> news:002401ca46b4$ed6ad6a0$c84083e0$@com...
>> Hello all,
>>=20
>> I'm trying to display a div, only when some php value is set.
>> Since this will be near html, I'd like to keep it on one line. So, I'd
>> love
>> to use shortcuts and a ternary operator for the effect.
>>=20
>> I'm having something like this right now, but the div still appears
>> even if
>> the error is NOT set.
>>=20
>> '
>> .$erros['anexo'].'' :''; ?>
>>=20
>> :(
>>=20
>> Can I have your help with the right syntax ?
>>=20
>>=20
>> Regards,
>> The newbie on a Humpty Dumpty wall,
>> M=E1rcio
>>=20
>>=20
>>=20
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
>=20
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20



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

RE: Re: ternary operator sintax help

am 06.10.2009 22:15:29 von talofo talofo

Absolutely. ;) I was reporting to ashley teachings. :-)

Philip, thanks for the tip.

:-)
Thank you all,
M=E1rcio

> -----Original Message-----
> From: Tom Worster [mailto:fsb@thefsb.org]
> Sent: ter=E7a-feira, 6 de Outubro de 2009 21:10
> To: MEM; php-general@lists.php.net
> Subject: Re: [PHP] Re: ternary operator sintax help
>=20
> just as ashley said it.
>=20
>=20
> On 10/6/09 3:26 PM, "MEM" wrote:
>=20
> > Sorry all,
> > It's ok. The sintax:
> >
> > > > class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>
> >
> > Was right all the time.
> >
> > Anyway, I've learn something new: having a var with '' is not the
> same thing
> > as not been unset. So we must pay attention on what cases we use
> isset, or
> > !empty.
> >
> >
> > Thanks a lot,
> > M=E1rcio
> >
> >> -----Original Message-----
> >> From: Jo=E3o C=E2ndido de Souza Neto =
[mailto:joao@consultorweb.cnt.br]
> >> Sent: ter=E7a-feira, 6 de Outubro de 2009 19:53
> >> To: php-general@lists.php.net
> >> Subject: [PHP] Re: ternary operator sintax help
> >>
> >> > >> class=3D"mensagemErro">'.$erros['anexo'].'' :''); ?>
> >>
> >> ""MEM"" escreveu na mensagem
> >> news:002401ca46b4$ed6ad6a0$c84083e0$@com...
> >> Hello all,
> >>
> >> I'm trying to display a div, only when some php value is set.
> >> Since this will be near html, I'd like to keep it on one line. So,
> I'd
> >> love
> >> to use shortcuts and a ternary operator for the effect.
> >>
> >> I'm having something like this right now, but the div still appears
> >> even if
> >> the error is NOT set.
> >>
> >> '
> >> .$erros['anexo'].'' :''; ?>
> >>
> >> :(
> >>
> >> Can I have your help with the right syntax ?
> >>
> >>
> >> Regards,
> >> The newbie on a Humpty Dumpty wall,
> >> M=E1rcio
> >>
> >>
> >>
> >> --
> >> 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
> >



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