1
votes

I have written a function that will query the database. The sql statement includes a where clause. However, I keep getting this error

"Message: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'home'., SQL state S0022 in SQLExecDirect".

The column name should be banner_category while "home_banner) is the value.

How should I go about achieving it?

public function get_landing_banners()
    {
        $query = $this->db->query(
            'SELECT *
             FROM o2o_banner
             WHERE banner_category='home_banner'');
        $data   =   array();
        foreach ($query->result_array() as $row) 
        {
            $data[] = $row;
        }
        return $data;  
    }
2

2 Answers

1
votes

If you want to return an array try this:

public function get_landing_banners()
{
    $this->db->select('*')->from('o2o_banner')->where('banner_category', 'home_banner');
    $q = $this->db->get();
    if ($q->num_rows() > 0) {
    return $q->result_array();
    }
}
0
votes

Try this coding

public function get_landing_banners()
    {
        $query = $this->db->query(
            'SELECT *
             FROM o2o_banner
             WHERE banner_category="home_banner"');
        $data   =   array();
        foreach ($query->result_array() as $row) 
        {
            $data[] = $row;
        }
        return $data;  
    }