Reply to Re: not displaying null data when using number_format

Your name:

Reply:


Posted by linda on 11/01/06 18:47

"Steve" <no.one@example.com> wrote in message
news:XG52h.115$AR2.0@newsfe04.lga...
>| I'm going to need to polish that hallo for you ;-) You've come to the
> | rescue once again. This one was driving me nuts! I tried all sorts of
> | search patterns for how to not display null data with a number_format,
> but
> | couldn't find anything. And when I tried myself with if statement, I
> just
> | kept getting the same result, i.e entire data for that id being removed.
> I
> | actually woke up in the middle of the night last night with a "I wonder
> if
> | this will work" scenario, and then couldn't go back to sleep until I got
> up
> | and tried it. ;-)
>
> i've had nights like that too. we are all still learning...or at least
> should be: whether it be the language itself or how to effectively apply
> it
> to ever increasingly difficult problems.
>
> | Ok now that you've shown me how to do it, could you translate what's
> | happening for me, if you don't mind that is? I think I know what's
> going
> | on, but not entirely sure, ;-) and don't wont to show the world my lack
> of
> | knowledge in case I'm wrong by posting what I think. lol... vanity and
> all
> | that!
>
> perhaps this will provide you with a "v-8" moment...
>
> if ($this)
> {
> // do this
> }
>
> you simply were telling php that "do this" included not only properly
> formatting your price, but also outputting your html as well. you just
> needed "do this" to only properly format your price and NOT you html as
> well. notice the difference:
>
> $price = '';
> if ($price)
> {
> $price = number_format(123.456, 2);
> echo '<pre>' . $price . '</pre>';
> }
>
> versus:
>
> $price = '';
> if ($price)
> {
> $price = number_format(123.456, 2);
> }
> echo '<pre>' . $price . '</pre>';
>
> the example i gave is called a ternary operation (operator). it's similar
> to
> a single-line if/else statement that returns a value to a variable. i used
> it to save space and make sure that the code reader/editer/reviewer/you
> would understand that the condition was only applied to price and NOT the
> html output. the second example will suffice as well since neither a '' or
> a
> 0 price needs to be formatted.
>
> do the above examples make sense?
>
>

Yep I understand it now! Thank you for explanation, it's much appreciated.
This is like when learnt to surf in my teens, lol very painfully and slowly.
So tell me, when you first started learning php, how many times did you
rebuild that site after you learnt a better way of doing something? ;-0

Talk about learning curve, I'll have the bl**dy arc at this rate!

Best wishes,
Linda

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация