PHP/MYSQL CODE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattuk17
Forum Newbie
Posts: 1
Joined: Mon Sep 08, 2003 4:59 am
Location: Scotland UK

PHP/MYSQL CODE

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Post Reply