[英]PHP Using dropdown to filter mysql table, without js or form
I'm trying to select a value from a dropdown to limit a mysql table selection, without JS, directly from a page (so, NOT from a form, but using an action tag). 我试图从一个下拉列表中选择一个值,以限制直接从页面上(而不是从表单中,而是使用动作标签)不带JS的mysql表选择。 Problem is, dropdown works, redisplay works, but I can't get the selected value into $_GET(sel_type). 问题是,下拉列表有效,重新显示有效,但是我无法将所选值放入$ _GET(sel_type)中。 Can anybody help? 有人可以帮忙吗?
echo " <td> </td>
<td><a href='".$_SERVER['PHP_SELF']."?sel_type=$sel_type'><b>
<select name='s_type' type='text' title='Alleen het geselecteerde item-type zien?' value='".$sel_type."'> ";
while($fetch_type = mysql_fetch_array($droptype)) {
echo " <option id ='" . $fetch_type['type_id']."' value='" . $fetch_type['type_id']."' ";
if ($sel_type==$fetch_type['type_oms']) echo "selected='selected'";
echo ">" . $fetch_type['type_oms']."</option>";
};
echo " </select></a></b></td>";
Without JS
you need a form
to submit the value of the select
: 如果没有JS
,则需要一个form
来提交select
的值:
if( isset( $_GET['s_type'] ) ){
//do something with the select here
$sel_type = $_GET['s_type'];
}
echo "<form action='".$_SERVER['PHP_SELF']."' method='GET' id='frm' name='frm'>";
echo " <td> </td>
<td><b>
<select name='s_type' title='Alleen het geselecteerde item-type zien?' onchange='document.frm.submit()'> ";
while($fetch_type = mysql_fetch_array($droptype)) {
echo " <option id ='" . $fetch_type['type_id']."' value='" . $fetch_type['type_id']."' ";
if ($sel_type==$fetch_type['type_oms']) echo "selected='selected'";
echo ">" . $fetch_type['type_oms']."</option>";
};
echo " </select></a></b></td>";
echo "</form>";
You need at least a <form>
tag to get a select
tag working without JS. 您至少需要一个<form>
标记才能使select
标记在没有JS的情况下工作。 And you can't use a select
block element inside an inline a
element. 你不能用一个select
块元素内联内a
元素。 And a select
field does not have an attribute type
and a value
attribute neither. select
字段也没有属性type
和value
属性。
echo " <td> </td>
<td>
<form method=\"GET\" action=\"".$_SERVER['PHP_SELF']."\"><select name=\"sel_type\" title=\"Alleen het geselecteerde item-type zien?\"> ";
while($fetch_type = mysql_fetch_array($droptype)) {
echo " <option id ='" . $fetch_type['type_id']."' value='" . $fetch_type['type_id']."' ";
if ($sel_type==$fetch_type['type_oms']) echo "selected='selected'";
echo ">" . $fetch_type['type_oms']."</option>";
};
echo " </select></form></td>";
To anybody out there, who is interested in the "impossible": I've solved my own question, without the use of JS or Form/submit, so you can can use it anywhere, incl server-side. 对于那些对“不可能”感兴趣的人:我已经解决了自己的问题,无需使用JS或Form / submit,因此您可以在任何地方使用它,包括服务器端。 The answer is something I'm using everyday (in menu's) and I still could not make the connection, until today. 答案是我每天都在使用菜单(在菜单中),但直到今天我仍然无法建立连接。 The solution includes some fancy CSS, which you can simplify, if you want the look-and-feel of a normal dropdown box. 该解决方案包括一些精美的CSS,如果您需要普通下拉框的外观,则可以简化这些CSS。 Here is the php code, followed by the css: 这是php代码,后跟CSS:
echo "<td><ul id='dropselect' class='droptable'>
<li class='droptable'><a href='".$_SERVER['PHP_SELF']."?sel_type=All types' title='Click one of the types in the list, to limit the db selection'><span>All types</span></a>
<ul>";
while($fetch_type = mysql_fetch_array($droptype)) {
echo "<li><a href='".$_SERVER['PHP_SELF']."?sel_type=".$fetch_type['type_desc']."'><span>".$fetch_type['type_desc']."</span></a>";
};
echo "</li></ul></ul></td>";
Here is the CSS; 这是CSS; you can copy it straight into your styleheet: 您可以将其直接复制到样式表中:
ul#dropselect,ul#dropselect ul{
margin:0;list-style:none;padding:0;background-color:#dedede;border-width:1px;border-style:solid;border-color:#5f5f5f;
-moz-box-shadow:3.5px 3.5px 5px #000000;
-webkit-box-shadow:3.5px 3.5px 5px #000000;
box-shadow:3.5px 3.5px 5px #000000;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;}
ul#dropselect ul{
display:none;position:absolute;left:0;top:100%;
-moz-box-shadow:3.5px 3.5px 5px #000000;
-webkit-box-shadow:3.5px 3.5px 5px #000000;
box-shadow:3.5px 3.5px 5px #000000;
background-color:#79beff;border-radius:6px;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-color:#d4d4d4;padding:0 10px 10px;}
ul#dropselect li:hover>*{
display:block;}
ul#dropselect li{
position:relative;display:block;white-space:nowrap;font-size:0;float:left;}
ul#dropselect li:hover{
z-index:1;}
ul#dropselect ul ul{
position:absolute;left:100%;top:0;}
ul#dropselect{
font-size:0;z-index:999;position:relative;display:inline-block;zoom:1;padding:0;
*display:inline;}
* html ul#dropselect li a{
display:inline-block;}
ul#dropselect>li{
margin:0;}
ul#dropselect a:active, ul#dropselect a:focus{
outline-style:none;}
ul#dropselect a{
display:block;vertical-align:middle;text-align:left;text-decoration:none;font:bold 15px Trebuchet MS;color:#55aaff;text-shadow:#FFF 0 0 1px;cursor:pointer;padding:10px;background-color:#c1c1c1;background-image:url("mainbk.png");background-repeat:repeat;background-position:0 0;border-width:0 0 0 1px;border-style:solid;border-color:#C0C0C0;}
ul#dropselect ul li{
float:none;margin:10px 0 0;}
ul#dropselect ul a{
text-align:left;padding:2px;background-color:#79beff;background-image:none;border-width:0;border-radius:0px;-moz-border-radius:0px;-webkit-border-radius:0px;font:15px Tahoma;color:#ffffff;text-decoration:none;}
ul#dropselect li:hover>a,ul#dropselect li a.pressed{
background-color:#79beff;border-color:#C0C0C0;border-style:solid;color:#ffffff;text-shadow:#FFF 0 0 1px;background-image:url("mainbk.png");background-position:0 100px;text-decoration:none;}
ul#dropselect span{
display:block;overflow:visible;background-position:right center;background-repeat:no-repeat;padding-right:2px;}
ul#dropselect ul li:hover>a,ul#dropselect ul li a.pressed{
background-color:#FFFFFF;background-image:none;color:#0978b3;text-decoration:none;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.