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
Add a sign-up feature to a flat file login script
I'm working on a flat file login script and I would like to add a sign-up feature to it with a email
BAPI BBP_INB_DELIVERY_CREATE - material number missing in delivery
Hi Experts,
I was able to successfully create an Inbound delivery with reference to a PO
Pop-up Banner
Hello Friends,I need to use banner in our client site.Example: www.example.com if i enter this site
Simple AND question
Hello,
I've got following code:
Code: if(strpos($row[13],"http://")
Upload, SSL and more php help
I recently just installed a ssl cert and do i use https for the whole site or just for the checkout.
help with image text
Hi ...
see i need the text of the name and number to start in the center and always be in the
whats wrong with my code please help!!!
this is the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link res
Newb advice
Hi all,
I'm a flash front end designer and I've taken on a project that needs some back end p
Something like an INI editor or a DelimitedText-Editor
Hi all,
Am very, very, very new to PHP and not sure if I should be posting this to a Javascri
Problem in String replace program's output
Hi all,
I was trying to make a program which accepts a string and replaces it with another stri