You are here: Re: If ... else that does not work « PHP Programming Language « IT news, forums, messages
Re: If ... else that does not work

Posted by Chris Hope on 10/31/44 11:16

Geoff Berrow wrote:

> I noticed that Message-ID: <neaje.4549$Rr3.236@read1.cgocable.net>
> from Joe Blow contained the following:
>
>>Brilliant, many thanks to both of you. As I suspected, it is a bit
>>obvious once it is pointed out. I had it your way the other day and
>>changed it for some reason when struggling with something else.
>
> When you are testing every element of an array (in this case the
> $_POST
> array) you may find it more efficient to use a loop.
>
> $missing="";
> foreach($_POST as $key=>$value){
> if($value==""){
> $missing="<li>$key</li>";
> }
> }
>
> if ($missing!=""){
> echo "Oops, you missed out <ul>$missing</ul>"
> }
>
> Untested.

Or you could do it like this, if you only require some of the fields to
be completed:

foreach(array('foo', 'bar', 'baz') as $fieldname) {
if($_POST[$fieldname] == '') {
...
}
}

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

 

Navigation:

[Reply to this 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

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