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
Convert .fdf to .pdf
I currently have a web form that uploads the form data to an .fdf file and emails it.
However
Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",
substr(I_NAME, IN
how to query data from website using VC?
I want to query some datum from a website,so I need a program to read data from a .csv file, and ass
writing my own sobel filter convolution - something is wrong
I am trying to keep it very simple, I cant see anything wrong with my logic, could anybody help poin
upload only text files
hi guys i want to upload only text like like (pdf,note pad and ofiice files) so can any one please t
Parse Error Help
Hello, I got the parse error "Parse error: syntax error, unexpected ',' in register.php on line
validating url
im trying to validate url's sent to me by a form
the url's im collecting are for placing banners
Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to
Create PHP table grid help, please
I have a MySQL database setup, now it's time for the table (gridview) design in php. Here's the prob
Insert to MySQL inside foreach
Hey.
I am parsing some html, and putting inside an html db.
I need to create a randomized inte