You are here: Re: A query from $_POST using foreach « All PHP « IT news, forums, messages
Re: A query from $_POST using foreach

Posted by Steve on 11/08/06 17:07

"kenoli" <kenoli@igc.org> wrote in message
news:1163002666.669348.15710@k70g2000cwa.googlegroups.com...
| I'm trying to create a query from a $_POST variable where the user may
| not have included a value in every form field. I need to have the
| first" set" variable at the beginning and the rest following it
| separated by an AND. Something like:
|
| val1 AND val2 . . . AND val(last)
|
| If I do something like:
|
| foreach ($_POST as $key = $val) {
|
| query .= "$val AND ";
|
| }
|
| or
|
| foreach {$_POST as $key = $val) {
|
| query .= "AND $val ";
|
| }
|
| I end up with an extra AND at the beginning or end.
|
| e.g.:
|
| val1 AND val2 . . . AND val(last) AND
|
| or
|
| AND val1 AND val2 . . . AND val(last)
|
| How can I tell it to treat the first or last occurence without the AND?

$query .= explode(" AND ", $_POST);

easy as that, however i assume given the lack of FIELD = VALUE in your
example, that you are building a list. in that case, it is more efficient to
do:

$query .= "WHERE someField IN ('" . explode("', '", $_POST) . "')";

hth,

me

 

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

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