1

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; 
 }
Pankaj
10.2k40 gold badges152 silver badges299 bronze badges
asked Jan 22, 2016 at 7:08

2 Answers 2

1

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();
 }
}
answered Jan 22, 2016 at 7:21
Sign up to request clarification or add additional context in comments.

Comments

0

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; 
 }
answered Jan 22, 2016 at 7:19

1 Comment

Thanks for your help. But I tried this and it have the same error.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.