0

I am using codeigniter with php. I want to get values from database table by comparing a column. The problem is the value coming from html code to compare with column is checkbox value and array. I want something like it, HTML

<input type="checkbox" name="car[]" value="Audi">Audi<br>
<input type="checkbox" name="car[]" value="BMW">BMW<br>
<input type="checkbox" name="car[]" value="Ford">Ford<br>

and code in codeigniter model is $this->db->where('car_name ==', $car[]); $this->db->get('cars');

3
  • How do you save values within your database Commented Jul 31, 2015 at 9:55
  • $this->db->where_in('car_name',$cararray); Commented Jul 31, 2015 at 9:57
  • Yes, It's working with $this->db->where_in('car_name', $car);.Thank you. Commented Jul 31, 2015 at 10:03

2 Answers 2

3

Use where_in -

$this->db->where_in('car_name', $car);
Sign up to request clarification or add additional context in comments.

Comments

1

Try this...

Generates a WHERE field IN ('item', 'item') SQL query

$names = array('Frank', 'Todd', 'James');
$this->db->where_in('username', $names);
// Produces: WHERE username IN ('Frank', 'Todd', 'James')

Ref:https://ellislab.com/codeigniter/user-guide/database/active_record.html

Comments

Your Answer

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.