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
First root of a number
Hi,
I can't find any function in php to give me the first root of a number.
Is there any
storing video files into mysql in php
hi
i have my video files in my folder ,
i have to store the path of the videos into db an
Simple code help with redirects
I am trying to figure out a redirect script that detects if the browser is IE 7 and if it does, redi
UDP Multicast question
Hey,
Im not really in the know when it comes to network related programming and activitie
Page not Loading After Test
Hey All
It seemed that an inlcude statement wasn't working for some reason, so I tried a more
mysql_real_escape_string making variable equal nothing
i post a form and i post the variable:
Code: $var = $_POST[variable];then i echo $var its what i
Content-Disposition: attachment; filename=... not working as i thought it should
taken the following code from the php.net site the script is not working.
what is not happeni
recrawling
Can anyone suggest me how may i know a page is updated before it is being downloaded, so that i can
convert pps to wsf with php'how?
hi
i want to convert with php
PowerPoint file to swf file(flash)
how please?
thank!!!
php + mysql count consecutive data
I have a database of values and I want to work out how to display them if the values match a consecu