[英]Option Select value to select all
I am trying to make option select for my page and I have added php in it so option will not change after submission but I want to add value=any so on selected item ANY it will select all from the database. 我正在尝试为我的页面选择选项,并且我已经在其中添加了php,因此选项在提交后不会更改,但是我想添加value = any,所以在选定的项目ANY它将从数据库中全部选中。
<option value="" selected>ANY</option>
<option <?php if ($_GET['siz'] == '640 x 480') { ?>selected="true" <?php }; ?>value="640 x 480">640x480</option>
<option <?php if ($_GET['siz'] == '800 x 600') { ?>selected="true" <?php }; ?>value="800 x 600">800x600</option>
<option <?php if ($_GET['siz'] == '1024 x 768') { ?>selected="true" <?php }; ?>value="1024 x 768">1024x768</option>
</select>
When "ANY" is selected it will show all the data from the database 选择“ ANY”时,它将显示数据库中的所有数据
if(isset($_GET['siz'])){
$siz = $_GET['siz'];
// My Query
SELECT * FROM data where size='$siz'
Now tell me what should I add in the value="?"
现在告诉我应该在
value="?"
添加什么value="?"
Thanks in Advance 提前致谢
You can give value for ANY
to anything as you like. 您可以根据自己的喜好为
ANY
事物赋予价值。 For example, 例如,
<option value="any" selected>ANY</option>
and in the php file you have to check whether the selected one is any
or not using the value of the option. 在php文件中,您必须使用该选项的值检查所选的对象是否是
any
一个。
In this example do like, 在这个例子中,
if(isset($_GET['siz'])){
$siz = $_GET['siz'];
if($siz=='any')
{
SELECT * FROM data;
}
}
You have some ways to solve it: Can dynamically make the sql request, the the "any" value will be none. 您有一些解决方法:可以动态发出sql请求,“ any”值将为none。 and
和
if(!$siz)
{
sql = "SELECT * FROM data;"
}
}
or you can change sql to 或者您可以将sql更改为
SELECT * FROM data where size in ($siz)
and "any" value will be: ' "640 x 480","800 x 600","1024 x 768" ' 和“ any”值将为:““ 640 x 480”,“ 800 x 600”,“ 1024 x 768”'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.