Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中获取空值的值_Php_Sql - Fatal编程技术网

如何在PHP中获取空值的值

如何在PHP中获取空值的值,php,sql,Php,Sql,我有一个多选列表。当用户不选择任何选项时,应显示所有文章的相关信息。 我在我的表格中添加了一个默认值ALL,如下所示: <?php $user = $app['security']->getToken()->getUser(); $default = 'ALL'; $form = $app['form.factory']->createBuilder('form',['lru' => [$default

我有一个
多选列表
。当用户不选择任何选项时,应显示所有文章的相关信息。 我在我的
表格中添加了一个默认值
ALL
,如下所示:

   <?php

    $user = $app['security']->getToken()->getUser();
            $default = 'ALL';
            $form = $app['form.factory']->createBuilder('form',['lru' => [$default]])->setMethod('GET')
 ->add('lru', 'choice', array(
                    'choices' => array(
                     $default => $default,

                    '\'ATSU\'' => 'ATSU', .... )

                    'required' => FALSE,
                    'empty_value' => 'ALL',
                    'empty_data' => NULL,
                    'multiple' => TRUE
                      ))
以下是我的职责:

if ($this->_count == 0) {
        $this->_sqlWhere.="`piecearticles`.`ID_Article`=`article`.`ID_Article` AND `piecearticles`.`Designiation`=`article`.`Designiation` AND `article`.`ID_LRU`=`lru`.`ID_LRU`";

        $this->_count++;
    } else {
        $this->_sqlWhere.="AND `piecearticles`.`ID_Article`=`article`.`ID_Article` AND `piecearticles`.`Designiation`=`article`.`Designiation` AND `article`.`ID_LRU`=`lru`.`ID_LRU`";
    }

    if (!empty($this->_lru)) {
        if(is_array($this->_lru) or ($this->_lru instanceof Traversable)) {
            $this->_sqlWhere.=" AND `lru`.`LRU` IN (" . implode(",", $this->_lru) . ")"; //='" . $this->_lru . "'";
        } else {
            $this->_sqlWhere.=" AND `lru`.`LRU`='" . $this->_lru . "'";
        }
    }
    //if (strpos($this->_sqlFrom,'article') == false) {
    $this->_sqlFrom.=', `article` ';
    //}
    if (strpos($this->_sqlFrom, 'lru') == false) {
        $this->_sqlFrom.=',`lru`';
    }
    //echo count($this->_lru);
} 
我对我的
查询
进行了
echo
,它返回
lru
lru
(全部)` 如何更改请求,使其根据默认值“ALL”取值。
谢谢。

我将冒昧地提供一个部分示例,希望能在一个专栏中解决您的问题。我假设用户要么只选中“全部”框,要么选择其他几个框

if (!empty($this->_lru)) {
        if((is_array($this->_lru) or ($this->_lru instanceof Traversable)) && ! in_array('ALL', $this->_lru)) {
            $this->_sqlWhere.=" AND `lru`.`LRU` IN (" . implode(",", $this->_lru) . ")"; //='" . $this->_lru . "'";
        } else if ($this->_lru != 'ALL' && ! in_array('ALL', $this->_lru)) {
            $this->_sqlWhere.=" AND `lru`.`LRU`='" . $this->_lru . "'";
        }
    }

此代码段应实现以下功能:如果根本没有选择任何框,则将其视为对所有框的查询。如果选择了“ALL”的任何框,则省略where子句。否则,如果
\u lru
是一个数组,则将该数组内爆为where子句。如果由于我不理解的原因,
\u lru
不是数组,请在where子句中使用它的值。

您提供的信息留下的问题多于答案。例如,
$this->\u sqlFrom
在哪里初始化?关于“ALL”:您通常通过省略相应的WHERE子句来实现这一点。@Adder我在类中初始化了_sqlForm(我更改了上面的问题)。您希望为哪个字段选择所有这些内容?您的代码中有一个问题,这不是一致使用的
$This->\u sqlWhere=“和
,并且,如果它是第一个添加到where子句中的,则不需要任何
。这就是为什么我经常用
where子句开始我的where子句,其中1=1
。我有5个其他字段,当用户不选择此字段时,请返回全部,另一个信息此字段是一个输入,然后我将其更改为列表以供多选。如何更改我的请求以与研究兼容
if (!empty($this->_lru)) {
        if((is_array($this->_lru) or ($this->_lru instanceof Traversable)) && ! in_array('ALL', $this->_lru)) {
            $this->_sqlWhere.=" AND `lru`.`LRU` IN (" . implode(",", $this->_lru) . ")"; //='" . $this->_lru . "'";
        } else if ($this->_lru != 'ALL' && ! in_array('ALL', $this->_lru)) {
            $this->_sqlWhere.=" AND `lru`.`LRU`='" . $this->_lru . "'";
        }
    }