No, I was only showing that you should use the value in <option> because often the value is different from the text. But in your case you can use this, althought it is not 'clean' programming practise.
So for your ALL selection, I would advise you to test the ALL value instead of testing the 'emptiness' of the other values.
Your dropdown list code here would be something like:[php]
<tr>
<td>Job Category:</td>
<td><select name="jobCategory">
<option selected='selected'>ALL</option>
<option>Accounting</option>
<option>Advertising</option>
<option>Agriculture</option>
<option>Banking</option>
</select></td>
</tr>
<tr>
<td>Job Location:</td>
<td><select name="jobLocation">
<option selected='selected'>ALL</option>
<option>Perlis</option>
<option>Penang</option>
<option>Kedah</option>
</select></td>
</tr>
[/php]
And the sql build would then be (I don't know what variable $keyword contains so I took it out, but you can put it back when required):[php]
$sql8 = "SELECT * FROM job";
if ($_POST['jobCategory'] == "ALL" AND
$_POST['jobLocation'] == "ALL") {
$data = mysql_query($sql8)
or die("Cannot execute query");
}[/php]
Ronald :cool:
Thanks again, Ronald, it is work... But now the problem happen in other query..
Below is my code for the search engine...
[PHP]<?php
//required file for database connection
include("config.php");
if (isset($_POST['keyword'])) {
$keyword = mysql_real_escape_string($_POST["keyword"]);
$jobCategory=$_POST["jobCategory"];
$jobLocation=$_POST["jobLocation"];
?>
<p align=center><center><font face='Arial' size='3'><strong>Search Results</strong></p>
<?php
$sql = "SELECT * FROM job";
$string1 = array();
$where1 = "";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string1[] = " jobTitle LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["jobCategory"]) AND !empty($_POST["jobCategory"]) AND ($category != Others))
$string1[] = " jobCategory LIKE '%".$_POST["jobCategory"]."%' ";
if (isset($_POST["jobLocation"]) AND !empty($_POST["jobLocation"]))
$string1[] = " jobLocation LIKE '%".$_POST["jobLocation"]."%' ";
if (!empty($string1))
$where1 = " WHERE ".implode("AND", $string1);// OR/AND
$sql1="SELECT * FROM job $where1";
$string2 = array();
$where2 = "";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string2[] = " jobTitle LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["jobCategory"]) AND !empty($_POST["jobCategory"]) AND ($category != Others))
$string2[] = " jobCategory LIKE '%".$_POST["jobCategory"]."%' ";
if (isset($_POST["jobLocation"]) AND $_POST['jobLocation'] == "All")
$string2[] = $_POST['jobLocation'] == "All";
if (!empty($string2))
$where2 = " WHERE ".implode("AND", $string2);// OR/AND
$sql2="SELECT * FROM job $where2";
$string3 = array();
$where3 = "";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string3[] = " jobTitle LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["jobLocation"]) AND !empty($_POST["jobLocation"]))
$string3[] = " jobLocation LIKE '%".$_POST["jobLocation"]."%' ";
if (!empty($string3))
$where3 = " WHERE ".implode("AND", $string3);// OR/AND
$sql3="SELECT * FROM job $where3";
$string4 = array();
$where4 = "";
if (isset($_POST["jobCategory"]) AND !empty($_POST["jobCategory"]) AND ($category != Others))
$string4[] = " jobCategory LIKE '%".$_POST["jobCategory"]."%' ";
if (isset($_POST["jobLocation"]) AND !empty($_POST["jobLocation"]))
$string4[] = " jobLocation LIKE '%".$_POST["jobLocation"]."%' ";
if (!empty($string4))
$where4 = " WHERE ".implode("AND", $string4);// OR/AND
$sql4="SELECT * FROM job $where4";
$string5 = array();
$where5 = "";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string5[] = " jobTitle LIKE '%".$_POST["keyword"]."%' ";
if (!empty($string5))
$where5 = " WHERE ".implode("AND", $string5);// OR/AND
$sql5="SELECT * FROM job $where5";
$string6 = array();
$where6 = "";
if (isset($_POST["jobCategory"]) AND !empty($_POST["jobCategory"]) AND ($category != Others))
$string6[] = " jobCategory LIKE '%".$_POST["jobCategory"]."%' ";
if (!empty($string6))
$where6 = " WHERE ".implode("AND", $string6);// OR/AND
$sql6="SELECT * FROM job $where6";
$string7 = array();
$where7 = "";
if (isset($_POST["jobLocation"]) AND !empty($_POST["jobLocation"]))
$string7[] = " jobLocation LIKE '%".$_POST["jobLocation"]."%' ";
if (!empty($string7))
$where7 = " WHERE ".implode("AND", $string7);// OR/AND
$sql7="SELECT * FROM job $where7";
// Call for this $sql
if ($keyword==""&&$_POST['jobCategory'] == "All"&&$_POST['jobLocation'] == "All") {
$data = mysql_query($sql)
or die("Cannot execute query");
}
elseif(!empty($keyword)&&!empty($jobCategory)&&!em pty($jobLocation)){
$data = mysql_query($sql1)
or die("Cannot execute query");
}
elseif(!empty($keyword)&&!empty($jobCategory)&&$_P OST['jobLocation'] == "All"){
$data = mysql_query($sql2)
or die("Cannot execute query");
}
elseif(!empty($keyword)&&$_POST['jobCategory'] == "All"&&!empty($jobLocation)){
$data = mysql_query($sql3)
or die("Cannot execute query");
}
elseif($keyword==""&&!empty($jobCategory)&&!empty( $jobLocation)){
$data = mysql_query($sql4)
or die("Cannot execute query");
}
elseif(!empty($keyword)&&$_POST['jobCategory'] == "All"&&$_POST['jobLocation'] == "All"){
$data = mysql_query($sql5)
or die("Cannot execute query");
}
elseif($keyword==""&&!empty($jobCategory)&&$_POST['jobLocation'] == "All"){
$data = mysql_query($sql6)
or die("Cannot execute query");
}
elseif($keyword==""&&$_POST['jobCategory'] == "All"&&!empty($jobLocation)){
$data = mysql_query($sql7)
or die("Cannot execute query");
}
?>[/PHP]
The search engine is such kind like below:
Keyword:
Job Category:
Job Location:
The users can search the result for job either fill in all the 3 field, 1 or 2 of the field or didn't fill in everything...
The problem now is the list menu for job category and job location which supposed empty last time now is change to All.. It only can execute the query $sql and $sql1, the others($sql2, $sql3, $sql4, $sql5, $sql6, $sql7) failed to search the job ...
Can u give me some guildeline?? Thanks..:)