Page 1 of 1

PHP/MYSQL CODE

Posted: Mon Sep 08, 2003 4:59 am
by mattuk17
Hello all,

Just creatign a search system on a site and i have stumbled over a small blip. Im sure one of you know the answer to this question.

Code: Select all

SELECT * FROM vacancies WHERE title = '$jobtype' AND region = '$region'"
Now $jobtype can sometimes be a search by ALL so how can i wildcard it instead of editing the whole SQL. eg i know you could search for hello in a cell by using %hello% but how can i make it for anything.

All help appreciated.

Matt

Posted: Mon Sep 08, 2003 5:15 am
by JayBird
why not code something like this

Code: Select all

if ($jobtype == "ALL") {
   $query = "SELECT * FROM vacancies WHERE title LIKE '%' AND region = '$region'";
} else {
   $query = "SELECT * FROM vacancies WHERE title = '$jobtype' AND region = '$region'";
}
you could actually remove the title LIKE '%' on the first SQL statement.

Mark