[英]Select dropdown value to get a populated data from database mysql
I have a populated dropdown list from mysql on one page. 我在一个页面上有一个来自mysql的填充下拉列表。
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. 我应该在php中编写什么代码,以便在选择下拉列表的值时,打开一个新页面并从mysql中获取数据,前提是我在数据库中需要字段。
<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>
has nothing to do with php or mysql ... you could add an "onchange" handler to your < select > element ... 与php或mysql无关...你可以在<select>元素中添加一个“onchange”处理程序...
<select onchange="javascript:someFunctionCallHere()">
a call to your forms submit() method should be what you want... 调用你的表单submit()方法应该是你想要的...
The answer is there is no PHP code to do what you're asking. 答案是没有PHP代码可以执行您所要求的操作。
You'll need two things: 1). 你需要两件事:1)。 Some javascript to hook into your form and 2).
一些javascript挂钩到你的表单和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): 这里有一些javascript要挂钩到表单中,假设jquery为了简洁(尽管你应该只选择一个ID或一个类,这将使选择器不那么讨厌):
$('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. 从那里,您将导航到renderer.php以及dataKey的$ _GET值。 render it as your will.
按照你的意愿渲染它。 If you want to open a new window, use a window.open call instead of setting location.href.
如果要打开新窗口,请使用window.open调用而不是设置location.href。
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' ) ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.