Hi,
I'm attempting to construct a search query in MySQL using multiple arguments, and I can't quite get it right.
I'm receiving the search arguments from a form, and using them to dynamically build my query.
Here is some background info:
I have a MySQL database containing job information. There are four columns I want to search:
- Job Title
- Job Type
- Job Description
- Job Location
Job Title: This is a 1-5 word title of the Job post. It can be different based on the way it was input
Job Type: This is a three letter code for the job type.
Job Description: This is a short description of the Job and duties
Location: This is a city or town
The user will search using a search form. The search form consists of three parts. Two Text fields, "keywords", and "location"; and a dropdown box listing about 20 Job Types. This will allow them to choose between the three letter codes for the job listings.
I would like to take the information from these three sections of the form and use them to search my database and return the most accurate records. I've tried several iterations of my query and it's either returning a lot of unrelated records, or not returning enough of the related ones. I've also been unable to account for the user intentionally leaving portions of the form blank.
My current query looks something like this:
select * FROM my_jobs_table WHERE category = 'User specified job type' OR job_title LIKE 'User specified Job keyword' OR job_description LIKE 'User specified Job keyword ' OR location LIKE "% User Specified Job Location%"
This just isn't working for me. Any Suggestions?