"Augusto Cesar Castoldi" <[EMAIL PROTECTED]> wrote:
> How can I do a advanced "string" search in my MySQL tables?
>
> Something like: I have a form with name, phone, age, e-mail... and I want
> to fill some of those and search in the database where name has "name
> typed in the form" and phone has "number typed in the form"....
>
> How Can I do that by a MySQL command?
>
> I don't know if it's somethin like: select * from users where name like
> "%$name%"

SELECT *
FROM users
WHERE name='$name' AND phone='$phone'

Only use the wildcard character '%' if you want to match records with *part*
of the form text contained in the field.  If some of the form fields may be
left blank, you'll have to build the SQL statement programatically so the
WHERE clause only contains the fields that are pertinent to the search.
Trying to work around that by using the '%' wildcard and including all
possible fields in the WHERE clause could greatly increase the time
necessary to run the query *and* it's not helping you learn how to program
efficiently in PHP.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to