简体   繁体   中英

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.

<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

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="?"

Thanks in Advance

You can give value for ANY to anything as you like. 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.

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

if(!$siz)
{
sql = "SELECT * FROM data;"
}
}

or you can change sql to

SELECT * FROM data where size in ($siz)

and "any" value will be: ' "640 x 480","800 x 600","1024 x 768" '

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM