sql query

Paul Robinson paul at iconoplex.co.uk
Wed Nov 13 15:59:29 GMT 2002

On Nov 13, Robin Garbutt <rob at portfoliodesign.net> wrote:

> can you use 'LIKE' and '=' in the same sql query?

> e.g
> if ($result = mysql_query("SELECT * FROM db WHERE name LIKE '$name%' OR id =
> '$id'", $db));
> {
>     blah blah blah
> }
> as the id don't seem to be querying...
> any suggestions?

id won't be checked if a result is returned on the LIKE - i.e., a name
matches, so $id won't be required because of the OR. If the id matches
you're expecting that don't match LIKE $name aren't coming back try putting
braces around each part of your query - WHERE (name LIKE '$name%') OR (id =
'$id') - and perhaps switching it around might help.

Paul Robinson

More information about the Ukfreebsd mailing list