creating a search function
Moderator: General Moderators
-
nineseveninteractive
- Forum Newbie
- Posts: 7
- Joined: Mon Jun 25, 2007 6:13 pm
creating a search function
Hi
I need to create a search function for a recruitment company website that allows the user to select from one drop down box whether the job is permanent, temporary or search all jobs and from that select the job category.
i have tried looking for tutorials on the web but cant find anything. Would anyone be able to point me in the right direction to find a tutorial to help me complete this?
it needs to work like the advanced search function on this webiste but only have the Job Type and Job Category search options:
http://www.spring.com/springpersonnel/c ... Search.asp
many thanks
I need to create a search function for a recruitment company website that allows the user to select from one drop down box whether the job is permanent, temporary or search all jobs and from that select the job category.
i have tried looking for tutorials on the web but cant find anything. Would anyone be able to point me in the right direction to find a tutorial to help me complete this?
it needs to work like the advanced search function on this webiste but only have the Job Type and Job Category search options:
http://www.spring.com/springpersonnel/c ... Search.asp
many thanks
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
-
nineseveninteractive
- Forum Newbie
- Posts: 7
- Joined: Mon Jun 25, 2007 6:13 pm
Hi
Thank you for the replies.
I have the database set up and the site is working, the only thing i have left to do on it is create this search feature.
What is the correct term for this type of search? I am searching the web for "php drop down list search" and various other similar search terms but can't find anything
many thanks
Thank you for the replies.
I have the database set up and the site is working, the only thing i have left to do on it is create this search feature.
What is the correct term for this type of search? I am searching the web for "php drop down list search" and various other similar search terms but can't find anything
many thanks
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Wha? This shouldn't be too hard. What you want to do is use the drop down to select a category. Then, you post that category and display all database entries that are marked with that category.nineseveninteractive wrote:What is the correct term for this type of search? I am searching the web for "php drop down list search" and various other similar search terms but can't find anything
- undecided name 01
- Forum Newbie
- Posts: 12
- Joined: Mon Jul 02, 2007 9:25 am
- Contact:
In case you're asking how to implement such a search:
Code: Select all
$db_result = mysql_query("
SELECT * FROM jobs
WHERE
job_type = '" . $_GET['job_type'] . "' AND
job_category = '" . $_GET['job_category'] . "'
");
while ($db = mysql_fetch_assoc($db_result)) {
print_r($db);
}
Last edited by undecided name 01 on Tue Jul 03, 2007 8:25 pm, edited 1 time in total.
- undecided name 01
- Forum Newbie
- Posts: 12
- Joined: Mon Jul 02, 2007 9:25 am
- Contact:
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- undecided name 01
- Forum Newbie
- Posts: 12
- Joined: Mon Jul 02, 2007 9:25 am
- Contact:
Thanks for the notes.
Assuming you're using Integer values for job_type and job_category in your
database, this is a solution:
Assuming you're using Integer values for job_type and job_category in your
database, this is a solution:
Code: Select all
$job_type = array_key_exists('job_type', $_GET) ? intval($_GET['job_type']) : 0;
$job_category = array_key_exists('job_category', $_GET) ? intval($_GET['job_category']) : 0;
if ($job_type == 0) {
die("Invalid Job Type.");
}
if ($job_category == 0) {
die("Invalid Job Category.");
}
$db_result = mysql_query("
SELECT * FROM jobs
WHERE
job_type = '" . mysql_real_escape_string($job_type) . "' AND
job_category = '" . mysql_real_escape_string($job_category) . "'
") or die("Unable to perform search.");
while ($db = mysql_fetch_assoc($db_result)) {
print_r($db);
}- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
array_key_exists() offers slightly differing functionality from isset() however.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Ooh. That's actually useful.feyd wrote:array_key_exists() offers slightly differing functionality from isset() however.
- undecided name 01
- Forum Newbie
- Posts: 12
- Joined: Mon Jul 02, 2007 9:25 am
- Contact:
Because array_key_exists() is older than isset() you prefer to use isset()?A lot of array functions are pretty old.
Of course these functions are different. But I think that they act similarly in this type of Form Handling.
Would you please offer a sample script to demonstrate the difference in a Form Handling situation? and a better reason to use isset()? What's wrong with array_key_exists()?
There are three situations where job_type is invalid:And for the invalid job type, you should actually use NULL instead of 0, since 0 is a valid integer.
- 1. It is not available;
2. It is not an Integer;
3. It is not in the valid domain (1..MAX(job_type));
I even rather to use "if ($job_type < 1)" to check for invalid values, since we do not use zero and negative values for primary keys in the database (job_type is a Foreign Key which references to job_type in the table job_types, job_type is primary key in the table job_types).