简体   繁体   English

PHP下拉框总是固定的

[英]PHP Drop Down Boxes always Isset

HI i have two drop down boxes which are used to filter data from a mysql table, the problem is the boxes always show as if they are set when i use isset to determin if any of them have any values selected. 嗨,我有两个下拉框,用于过滤来自mysql表的数据,问题是当我使用isset确定是否选择了任何值时,框始终显示为好像已设置。

Here is the code for the drop boxes. 这是投递箱的代码。

 <?php 
                       if (isset($_POST['referrer']) && $_POST['referrer'] != "referrer") {
                       $select = $_POST['referrer'];
                         }
                       ?>
                                    <select name="referrer">
                                    <option value="">Referrer</option>

                                      <?php
                       // Get records from database (table "name_list").
                       $list=mysql_query("select DISTINCT referrer from masterip_details WHERE country_code='GB' AND TRIM(IFNULL(referrer,'')) <> '' order by referrer DESC");
                       // Show records by while loop.
                       while($row_list=mysql_fetch_assoc($list)){
                       $referrer = $_POST['referrer']; ?>
                                      <option value="<?php echo $row_list['referrer']; ?>" <?php if($row_list['referrer']==$select){ echo "selected"; } ?>><?php echo $row_list['referrer']; ?></option>        
                                      <?php     
                       }
                       ?>
                                    </select>



 <?php 
                       if (isset($_POST['returning']) && $_POST['returning'] != "returning") {
                       $select2 = $_POST['returning'];
                         }
                       ?>
                                    <select name="returning">
                                    <option value="">Referrer</option>
                                      <?php
                       // Get records from database (table "name_list").
                       $list2=mysql_query("select * from repeater_drop_down order by id DESC");
                       // Show records by while loop.
                       while($row_list2=mysql_fetch_assoc($list2)){
                       $returning = $_POST['returning']; ?>
                                      <option value="<?php echo $row_list2['value']; ?>" <?php if($row_list2['value']==$select2){ echo "selected"; } ?>><?php echo $row_list2['title']; ?></option>     
                                      <?php     
                       }
                       ?>
                                    </select>

Now here are the isset elements of the code. 现在,这里是代码的isset元素。

$returning = $_POST['returning'];
$referrer = $_POST['referrer'];

 if (isset($returning, $referrer)){

 //code //

  elseif (isset($returning)){

   ///code //

  elseif (isset($referrer)){

  //code //

  else {

 //code   

        }

I haven't included the queries as they work fine but whether or not i select both drop down boxes the code automatically goes to the first isset for both variable even if only one of the boxes has a option selected. 我没有包括查询,因为它们工作正常,但是我是否同时选择了两个下拉框,即使只有其中一个框已选择选项,代码也会自动转到两个变量的第一个isset。

Any advice or suggestions would be appreciated. 任何意见或建议,将不胜感激。

You should check the value that was submitted with the form, not only whether or not the select POST value is set. 您不仅应设置select POST值,还应检查与表单一起提交的值。

The value of the referrer will be '' (an empty string) if it is submitted without changing the select. 如果在不更改选择的情况下提交,引荐来源网址的值将为'' (空字符串)。 Check for that instead. 而是检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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