【问题标题】:Failing to get correct fields from the database with PHP无法使用 PHP 从数据库中获取正确的字段
【发布时间】:2016-04-12 14:08:14
【问题描述】:

我想获取数据库中的行:

“l_area”为表格列

“in consignment”是表

并且限制“l_area”等于“area”变量中存储的值。

我的代码如下所示。即使 l_area 不等于 area,它也只会输出所有选中的项目。

    function get_all()
    {
        $area = $this->session->userdata('area'); 
        $this->db->select('l_area','d_area','description','dom','tom'); // the select statement
        $this->db->where('l_area' == $area);
        $q = $this->db->get('consignment'); // the table    
    }

【问题讨论】:

  • $this->db->where('l_area' == $area); 在我看来根本不合适。不应该是$this->db->where('l_area', $area);吗?

标签: php mysql database codeigniter session


【解决方案1】:

试试这个

public function get_all()
{
    $area = $this->session->userdata('area'); 
    $this->db->select('*'); // the select statement
    $this->db->where('l_area',$area);
    $query = $this->db->get('consignment'); // the table   
    $result = $query->result_array();

    print_r($result);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    相关资源
    最近更新 更多