php - 从两个表中选择数据时出错

标签 php mysql codeigniter

Error Number: 1096

没有使用表格 选择 *

$where = array();
            if($category){
                $where[] = 'subcategories.categories_id = '.$category;
            }
            if($value){
                $where[] = "subcategories.name LIKE '%".$value."%'";
            }
            $where = implode('and', $where);
            $this->db->query("select subcategories.*, categories.name as catname FROM subcategories JOIN categories ON categories.id = subcategories.categories_id where ".$where);
            $query = $this->db->get();

我正在加入两个表类别和子类别,动态 where condition.same 查询在 phpmyadmin 中工作,但在 codeigniter 中出现错误,在此先感谢

最佳答案

试试看

$query = $this->db->query("Your Query Here");
$query = $query->result();
print_r($query);

然后像这样编辑你的where条件

$where = '';
if($category){
     $where .= 'subcategories.categories_id = '.$category;
}
if($value){
     if($category) {
         $where .= " AND ";
     }
     $where .= "subcategories.name LIKE '%".$value."%'";
}

关于php - 从两个表中选择数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22555197/

相关文章:

php - mysql中的绑定(bind)参数

php - AH01215 : Failed loading/usr/lib64/php56/modules/ioncube_loader_lin. 所以:无法打开共享对象文件:没有这样的文件或目录:

php - 在相同列名的表中循环获取图像

javascript - 列出选定类别和价格范围内的产品

python - 基于FK的Django查询——get all,not any

php - 如何防止 CodeIgniters 打印 PHP 错误

javascript - 如何在数据表php中添加一个复选框

php - 当我利用 laravel 的 `RefreshDatabase` 特征通过 phphunit 运行数据库迁移时,Laravel 指定一个迁移文件夹

php - api 平台 - 无法为项目生成 IRI

MySQL 索引 - In 与 Equals 索引问题