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