2019-03-19 18:26:50 1720次浏览 3条回答 0 悬赏 10 金钱
$result = (new Query())->select([
    'ad_id',
    'ad_img',
    'ad_url',
    'ad_name',
    'start_time',
    'end_time'
])
    ->from('warehouse_ad')
    ->where($condition)
    ->andWhere('<','start_time',date('Y-m-d H:i:s',time()))
    ->andWhere('>','end_time',date('Y-m-d H:i:s',time()))
    ->orderBy('ad_sort')
    ->all();
PHP Warning – yii\base\ErrorException
Invalid argument supplied for foreach()
1. in D:\root\PHPTutorial\WWW\kjy\warehouse\vendor\yiisoft\yii2\db\Query.php at line 1006
9979989991000100110021003100410051006100710081009101010111012101310141015     * @return $this the query object itself
     * @see params()
     */
    public function addParams($params)
    {
        if (!empty($params)) {
            if (empty($this->params)) {
                $this->params = $params;
            } else {
                foreach ($params as $name => $value) {
                    if (is_int($name)) {
                        $this->params[] = $value;
                    } else {
                        $this->params[$name] = $value;
                    }
                }
            }
        }
        return $this;
2. in D:\root\PHPTutorial\WWW\kjy\warehouse\vendor\yiisoft\yii2\db\Query.php at line 1006 – yii\base\ErrorHandler::handleError(2, 'Invalid argument supplied for fo...', 'D:\root\PHPTutorial\WWW\kjy\ware...', 1006, ...)
3. in D:\root\PHPTutorial\WWW\kjy\warehouse\vendor\yiisoft\yii2\db\Query.php at line 599 – yii\db\Query::addParams('end_time')
4. in D:\root\PHPTutorial\WWW\kjy\warehouse\common\DataCache.php at line 766 – yii\db\Query::andWhere('>', 'end_time', '2019-03-19 18:22:52')

最佳答案

  • 回答于 2019-03-20 09:04 举报

    楼上正解,andWhere($condition, $params = []),三个参数值是作为$condition的数组,不存在三个参数的写法,用方法前要看下方法的使用呢。`/**

     * Adds an additional WHERE condition to the existing one.
     * The new condition and the existing one will be joined using the `AND` operator.
     * @param string|array|ExpressionInterface $condition the new WHERE condition. Please refer to [[where()]]
     * on how to specify this parameter.
     * @param array $params the parameters (name => value) to be bound to the query.
     * @return $this the query object itself
     * @see where()
     * @see orWhere()
     */`
    
    , 觉得很赞
  • 回答于 2019-03-23 15:55 举报
    1. `` > ### **## ### *****
您需要登录后才可以回答。登录 | 立即注册
PHP学院的中学生
副总裁

PHP学院的中学生

注册时间:2018-10-23
最后登录:2024-09-23
在线时长:168小时13分
  • 粉丝29
  • 金钱4725
  • 威望30
  • 积分6705

热门问题