0

I have a populated dropdown list from mysql on one page.

What code should i write in php so that on selection of dropdown list's value, a new page is opened and data is fetched from mysql, provided i have required fields in database.

<form name="form1">
<select>
<?php 
$con=mysql_connect("localhost","FreeUser","123456");
if(!$con)
{
die('Connection failed' . mysql_error());
}
mysql_select_db("human_resource", $con);
$sql1=mysql_query("SELECT eid_emp,name_emp FROM employee_details");
while ($data=mysql_fetch_assoc($sql1))
  {
    ?>
    <option name="drop1" checked value ="<?php echo $data['eid_emp'] ?>" >
    <?php echo $data['name_emp']; ?>
    </option>
  <?php 
  } 
  mysql_close($con);
  ?>
</select>
</form>
1
  • Added a javascript tag since this question involves some client side stuff... Commented Aug 20, 2011 at 1:38

3 Answers 3

1

The answer is there is no PHP code to do what you're asking.

You'll need two things: 1). Some javascript to hook into your form and 2). a way to render the resulting query.

here is some javascript to hook into the form, assuming jquery for brevity (although you should just give the select an ID or a class, which would make the selector less obnoxious):

$('form[name="form1"] select').change(function(){
     location.href='renderer.php?dataKey=' + $(this).val();
});

From there, you'll navigate to renderer.php along with $_GET value for dataKey. render it as your will. If you want to open a new window, use a window.open call instead of setting location.href.

Sign up to request clarification or add additional context in comments.

Comments

1

has nothing to do with php or mysql ... you could add an "onchange" handler to your < select > element ...

<select onchange="javascript:someFunctionCallHere()">

a call to your forms submit() method should be what you want...

3 Comments

I need to ask you a favor, can you just go through this link which has some php script which enables to what i asked in my above query. tizag.com/phpT/examples/formvar.php I just gone through the above example its working on the website but when i code it is has some issues, that no-index has been defined. I appreciate your help. Thanks
i read the example from your link. there is nothing in it that posts the form on selection of the drop down box ... additionally i can tell you that the desired effect can not be implemented in php ... php runs on the server ... the event that you want to handle is on the client ... so you will need some client-side script like javascript to do what you want ...
javascript: does not belong into an onchange etc. handler. Actually, the only reason why it's not an error is that something: defines a label in JavaScript (so it doesn't change anything if it's there).
0

Not a lot of information, but you could do something like this:

<form name="form1" method="POST" action="page.php">
<select onchange="form1.submit()">

Then in the head of your page

<?php 
if(count($_POST))
{
  // do stuff
  header( 'Location: http://somesite.com' ) ;  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.