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

mysql VARCHAR acting like INT
Hi, All.

I have a table that contains a varchar(10) column named weird_field. In this column

if statements problems
Hi. I'm trying to make a web form, but I kind of hit a dead end trying to figure out why it doesn't

Inserting Data into a MS Access DB using PHP.
As part of my uni course I am doing a placement at a company whom want me to create a client zone fo

Echoing ASCII code
I have a php page that splits a string into chars and then echoes the ASCII code for each char. I'm

(sub)screen resize modification doesn't work after ECC 6 EhP 4 installation
Hello,

We have previously extended the size of the custom data tab on PO transaction ME23

=> and <=
So I was digging through some code when I came across the <= operator. This is the first tim

problem with php mysql query
Hi guy's...

I'm totally lost here..because don't have any idea how to make a query for grab r

LSB (PHP 5.3) problem with static value!
hello,

i'm having a problem. static::$text variable gets lost at some point. can someone plea

default SAP userid
hi,, I just like to know if it is ok to use the default SAP user id (SAP*)?

New to PHP and just trying to understand a little code.
I hope I'm not annoying anyone or breaking the rules but I was wondering about this bit of code righ

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