我正在尝试进行高级搜索,我有这个工作,但我正在对每个 get 变量进行完整查询,这不好但它有效
现在我正在尝试根据 url 变量是否为空来构建查询。但我无法弄清楚我们为什么这不起作用。查询工作正常,因为我已经测试过了,我没有正确构建查询吗?
这是功能
public function search($man, $mod, $min, $max)
{
$this->currentLocation();
$bind = '';
$query .= 'SELECT listed_watches.*, watch.*, watch_images.* FROM listed_watches';
$query .= 'LEFT JOIN watch ON watch.Id = listed_watches.watchID';
$query .= 'LEFT JOIN watch_images ON listed_watches.url = watch_images.url';
$query .= 'WHERE listed_watches.sellto REGEXP :search';
if(!empty($man)){
$query .= 'AND listed_watches.manufacture = :man';
$bind .= "$smt->bindValue(':man', $man);";
}
if(!empty($mod)){
$query .= 'AND listed_watches.model = :mod';
$bind .= "$smt->bindValue(':mod', $mod);";
}
if(!empty($min)){
$query .= 'AND listed_watches.minPrice > :min';
$bind .= "$smt->bindValue(':min', $min);";
}
if(!empty($max)){
$query .= 'AND listed_watches.maxPrice < :max';
$bind .= "$smt->bindValue(':max', $max);";
}
$query .= 'GROUP BY listed_watches.id';
$smt = $this->pdo->prepare(''.$query.'');
$smt->bindValue(':search', "^[".$this->userLocation."]");
$bind;
return $smt->fetchAll();
}
当我搜索并输入选择一个 $man 和 $mon 我得到这个错误
Undefined variable: smt
Trying to get property of non-object in
这个错误是对这条线的裁判
$bind .= "$smt->bindValue(':mod', $mod);";