【问题标题】:how to search result in codeigniter using age and cast如何使用年龄和演员在codeigniter中搜索结果
【发布时间】:2016-06-28 11:01:33
【问题描述】:

这是我必须使用 mysql 和 codeigniter 搜索结果的模型,但它显示所有男性但未显示年龄并正确投射

 public function get_selected($age, $cast) {
        $this->db->select('*');
        $this->db->from('bride_groom_register');
        $this->db->like('age', $age);
        $this->db->or_like('cast', $cast);
        $this->db->where("gender='male'");
        $data = $this->db->get();
        if ($data->num_rows() > 0) {
            return $data->result_array();
        } else {
            return FALSE;
        }
    }

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    删除 likeor_like 在 where 条件中使用。如果您想提供性别,请在同一行中提供。

    $this->db->where("age LIKE %$age% or cast LIKE %$cast%");
    

    【讨论】:

      【解决方案2】:

      试试这个:

      $this->db->query("SELECT * FROM " . $this->db->dbprefix('bride_groom_register') . " WHERE gender = male AND age = '".$age."' AND cast = '".$cast."' ");
      

      希望对你有所帮助。

      【讨论】:

      • @yogesh 调用成员函数 dbprefix() 时出现空值错误
      • 感谢@yogesh 的快速回复,但假定列名性别为男性,因为列名错误是“where 子句”中的未知列“男性”
      • 对不起你想说的话。
      【解决方案3】:

      您为什么使用like 子句而不是where 子句?

      $this->db->where('age', $age);
      $this->db->where('cast', $cast);
      

      $this->db->where([
          'age' => $age, 
          'cast' => $cast
      ]);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-09
        • 1970-01-01
        • 2014-08-03
        • 1970-01-01
        • 1970-01-01
        • 2019-12-27
        • 1970-01-01
        • 2014-03-26
        相关资源
        最近更新 更多