Unable to display contents in Second Drop Down Box
Posted on
16th Feb 2014 07:03 pm by
admin
Hi All,
What I am trying to do is 2 dependent drop down boxes and when user selects submit button the values are to be passed to the database to run a insert query.
Right now, I am stuck with the second drop down box because it does not show up the values based on the selection in the first drop down box.
Important point here is " My second drop down box displays columns from a single row(returned from second query)"
Attached is my code please do suggest me the required changes to make and also I pasted the code here,
<?php
include("../include/dbcommon.php");
if(isset($_GET["country"]) && is_numeric($_GET["country"]))
{
$country = $_GET["country"];
$emp_number=$country;
echo($emp_number);
}
if(isset($_GET["state"]) && is_numeric($_GET["state"]))
{
$state = $_GET["state"];
$emp_positionheld=$state;
echo ($emp_positionheld);
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get">
<select name="country" onChange="autoSubmit();">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH Employee Names
$sql = "SELECT EmployeeNumber,LastName FROM employees";
$countries = mysql_query($sql,$conn);
while($row = mysql_fetch_array($countries))
{
echo ("<option value="$row[EmployeeNumber]" " . ($country == $row["EmployeeNumber"] ? " selected" : "") . ">$row[LastName]</option>");
}
?>
</select>
<?php
if($country != null && is_numeric($country) )
{
?>
<select name="state" onChange="autoSubmit();">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH Job Position helds For a Given Employee
$sql = "SELECT * FROM employee_positionheld WHERE EmployeeNumber = $country ";
$states = mysql_query($sql);
$row = mysql_fetch_array($states);
for($k=1;$k<=6;$k++)
{
echo("inside for");
$temp[$k]='Position held' . ' '.$k;
$queryvar=$temp[$k];
//echo($queryvar);
echo ("<option value="$row[$queryvar]" " . ($state == $row[$queryvar] ? " selected" : "") . ">$row[$queryvar]</option>");
}
?>
</select>
<?php
}
?>
</form>
MY EMPLOYEE_POSITION HELD TABLE looks like this
EmployeeNumber Employee Name Position held 1 Position held 2 Position held 3 Position held 4 Position held 5 Position held 6
34550 Suraj Entryleveltech1 Seniortech1 programmer1 0 0 0 0
No comments posted yet
Your Answer:
Login to answer
272
26
Other forums
Delete all from a table
I can not get the following code to work. If I run the sql statement in the db it will delete all t
Remove values in array2 from array1
I have two arrays.
Array 1 is where the array key holds various different numbers. For exampl
links using header()
Hi All
I'm not sure where to ask for help on this but I hope someone can offer some. I'm at
Custom array sort? asc then desc
Any ideas how I could sort this array? I've been trying for a while. Maybe with usort, but I have no
help with calculations on a flat text file
hello,
I have this code below that is attached to a flat file like this:
Email:LastName:FirstN
utf8_general_ci error ??
I have all kinds of data to be inserted in database table
//I am getting this error
Yo
[newb] Image hosting help.
Hey there, I'm new to php, I know some basics and i can code PWN, I'm only 14 but I'm interested in
Session problem?!?
Hello All! I am very new to the php world but I am working on fixing things that a previous programm
Transport data between itab and textfield on ALV event
Hallo,
I have a ALV Grid ( cl_gui_alv_grid ) and I also have hotspot click event with a h
PHP Multiples of 2, Show posts...not working (wordpress)
I have been using this code to show div.example with 6 li columns inside it, each li is a post with