Re: Doing a Multiple Search
| From: | Ernest E Vogelsinger | Date: | Tue, 04 Mar 2003 14:11:34 +0000 |
| Subject: | Re: Doing a Multiple Search | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138110@lists.php.net to get a copy of this message | ||
At 14:50 04.03.2003, Hunter, Jess spoke out and said:
--------------------[snip]--------------------
>Here is the Base Line I am working with:
>
>$Query="SELECT * from $TableName WHERE lastname='$Array[lastname] AND
>firstname='$Array[firstname]' ";
>
>What I ant to be able to do is a search on both the lastname and the
>firstname so if someone just puts in the last name it will display all
>people with the queried last name regardless of the first name. So for the
>visual representation
--------------------[snip]--------------------
$query = "select * from $tablename where " .
(!empty($array['lastname']) ? "lastname =
'{$array['lastname']}' " .
(!empty($array['firstname']) ? 'and ' : null) : null) .
(!empty($array['firstname']) ? "firstname =
'{$array['firstname']}'" ; null);
Note that you need to put curly braces around an array dereference if you
have it in a quoted string.
This doesn't work:
$s = "Some $array[sample]";
But this works:
$s = "Some {$array['sample']}";
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/