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 Like 26 Dislike
Previous forums Next forums
Other forums

Schedule editor
Hi,

I have a question related to Schedule editor.
If we schedule a BLS for every 30

Paypal
Hi all,

I have an advanced basic knowledge of php

I want to try something new for a s

duplicate record notification
In my database, after insertion of records, I want to know if the record inserted is duplicate or no

array & querys help/advice.
Ok so here goes , I have a mysql database and basically here's what I need to do.

// foreach

Do something every fifth time?
I'm trying to write a loop, but I want it to do something different after every fifth instance. Like

Socket Server
In my following socket server, I am trying to listen to a connection through port 12345 in my web br

how can i expire the submitted page using session.
hi,
i'm new to php world.
i'm using "post" method.
when i submit it,data goes to

Character Set Setup
Whats the best character set to use if you want every character to work, and also how do you make yo

Is it a good practice to store user info. in sessions?
I am making a user class for my script which stores all the user information in sessions. It takes u

Clean URLs
Hi I was wandering if anyone has ever implemented URLs on their PHP run website using URLS like wiki

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash