473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to code the <option> statement

127 100+
Below is the list menu of search engine.. How to code if i want to put
Expand|Select|Wrap|Line Numbers
  1. <option selected>ALL</option>
  2.  
Interface
Expand|Select|Wrap|Line Numbers
  1. <tr> 
  2.     <td>Job Category:</td>
  3.     <td><select name="jobCategory">
  4.         <option selected></option>
  5.         <option>Accounting</option>
  6.         <option>Advertising</option>
  7.         <option>Agriculture</option>
  8.         <option>Banking</option> 
  9. </select></td>
  10.   </tr>
  11.   <tr> 
  12.     <td>Job Location:</td>
  13.     <td><select name="jobLocation">
  14.         <option selected></option>
  15.         <option>Perlis</option>
  16.         <option>Penang</option>
  17.         <option>Kedah</option> 
  18. </select></td>
  19.   </tr>

php code
Expand|Select|Wrap|Line Numbers
  1. $sql8 = "SELECT * FROM job";
  2. elseif ($keyword== ""&&$jobCategory==""&&$jobLocation=="") {
  3. $data = mysql_query($sql8)
  4. or die("Cannot execute query");
  5. }
The code above is function, but when i add ALL between <option selected></option> as below:
<option selected>ALL</option>

it cannot function, so, can anyone give me some guildeline... Thanks..
Feb 14 '07 #1
5 1858
ronverdonk
4,258 Expert 4TB
Why don't you have a value attached to your <option> statements? How do you e.g. know that option Accounting has been selected?? The usual format to code an option statement is e.g.

Expand|Select|Wrap|Line Numbers
  1. <option value="Accounting">Accounting</option>
so you can check the existence of this value in the 'Category' field passed to you.

Also an option like <option selected>ALL</option> is coded as
Expand|Select|Wrap|Line Numbers
  1. <option value='ALL' selected='selected'>ALL</option>
My question here is, what are you trying to accomplish with these options? In my opinion none of your selects/options will work.

Ronald :cool:
Feb 14 '07 #2
bb nicole
127 100+
Why don't you have a value attached to your <option> statements? How do you e.g. know that option Accounting has been selected?? The usual format to code an option statement is e.g.

Expand|Select|Wrap|Line Numbers
  1. <option value="Accounting">Accounting</option>
so you can check the existence of this value in the 'Category' field passed to you.

Also an option like <option selected>ALL</option> is coded as
Expand|Select|Wrap|Line Numbers
  1. <option value='ALL' selected='selected'>ALL</option>
My question here is, what are you trying to accomplish with these options? In my opinion none of your selects/options will work.

Ronald :cool:
Emm...Isn't both
Expand|Select|Wrap|Line Numbers
  1. <option>Accounting</option>
and
Expand|Select|Wrap|Line Numbers
  1. ]<option value="Accounting">Accounting</option>
is same??
Actually i didn't very know what the use of put the value in the option, so i didn't use it... Usually, i use
Expand|Select|Wrap|Line Numbers
  1. <option>Accounting</option>
, i use it in register form, search engine and so on... And in register form, what i'm select will enter to database... And in search engine, it will display the result according to what i'm select...
The register form and search engine can work properly, so i don't know whether is have a problem or not...

What i want to do is when the users click the search button without key in anything(keyword, or job category or job location), all the job in database will display out as a result.

Expand|Select|Wrap|Line Numbers
  1. $sql8 = "SELECT * FROM job";
  2. if ($keyword== ""&&$jobCategory==""&&$jobLocation=="") {
  3. $data = mysql_query($sql8)
  4. or die("Cannot execute query");
  5. }
I want to add ALL between <option selected></option> in list menu, so the user will know all the job will display out when they didn't key in anything and click the search button. But the code above will leave a blank if the user didn't key in anything.
Although it can display all the job after the user click the search button, but the users would not know that all the job will display if they just click the search button..

So, what should i do now besides have a value attached to my <option> statements??
Thanks..
Feb 14 '07 #3
ronverdonk
4,258 Expert 4TB
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:
Feb 14 '07 #4
bb nicole
127 100+
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..:)
Feb 15 '07 #5
ronverdonk
4,258 Expert 4TB
I would start to echo the content of $sql2 ... etc. so you can see that the statement is correct. Chance is that there is something that is not quite what you would expect.

When you are sure it is correct, only test e.g. $sql2 and build some echoes around it to see if and how it executes.

But first echo the content of the statement to be certain.

Ronald :cool:
Feb 16 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
6
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works...
5
ronverdonk
by: ronverdonk | last post by:
I don't know much of JavaScript, hence this question. I have an select list with an option entry<option value="This is a value"><This is a value</option> When I try to handle the option value, when...
4
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
7
by: Shrek | last post by:
I have a drop down on a web page and want to change the cursor from default to pointer, so my style definition has style ="cursor: pointer;" the drop down though fails to change from the...
4
by: pplers | last post by:
Here is config.php: <?php //The vars are all ok. $dbhost = 'localhost'; $dbname = 'forum'; $dbuser = 'toor'; $dbpass = ''; ?> Here is a part of functions.php: <? require "config.php"; //It...
14
by: The Natural Philosopher | last post by:
This is a nasty one and I can't see my way out of it. I have a bunch of select statements in a form, and each select statement has an onchange="do_something(this)" in it, and this works...
14
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.