0

I am passing an array through jQuery like this

$.ajax({
    url: "<?php echo base_url();?>index.php/autocomplete/test_search?added_ids[]="+ids,

.....

Here is the network text from chrome

..../autocomplete/test_search?added_ids[]=5190,3574,5369&term=s

I have to catch this array in my controller to run a query like

$selected = $this->input->get('added_ids');

$this->db->select('first_nm, last_nm , title');
$this->db->where_not_in('my_id', $selected);

But for the first entry in the array it is working. The next element are not being excluded in the where_not_in section. Can you please help me where am I doing it wrong?

2
  • Pass it as a string & than convert the values into an array using implode or join function. Commented Jan 9, 2014 at 13:55
  • send as added_ids="+ids Commented Jan 9, 2014 at 14:01

3 Answers 3

1

use -

ids.join(", ");

and pass them as a string

Sign up to request clarification or add additional context in comments.

Comments

1

In your Ajax call

$.ajax({
    url: "<?php echo base_url();?>index.php/autocomplete/test_search?added_ids="+ids.join("_"),

In controller

$selected = $this->input->get('added_ids');
$selected=explode('_',$selected);

$this->db->select('first_nm, last_nm , title');
$this->db->where_not_in('my_id', $selected);

You can use .join() to combine array elements .In your controller you can get element by using explode()

Comments

0

Try where_not_in() function expects an array not a string.

$selected = $this->input->get('added_ids');
 $ids = explode(',',$selected[0]);
 $this->db->select('first_nm, last_nm , title');
 $this->db->where_not_in('my_id', $ids);

more info here

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.