开发者

Select dropdown value to get a populated data from database mysql

I have a populated dropdown list from mysql on one pa开发者_运维百科ge.

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>


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.


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...


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' ) ;  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜