0

I'm using CodeIgniter and trying to use an array in the WHERE clause to return only rows whose id is found in the array.

Submitted by form:

$arrTID = $this->input->post('Present'); print_r($arrTID);

output:

Array(
 [0]=>FMM003
 [1]=>30089
 [2]=>30097
)

query:

$query = $this->db->query("
    select TraineeID
    from tbl_attendance_processed
    where TraineeID IN $ID
    and attnDate='$atnDate'
");
$res = $query->result_array();

I need the query to return the TraineeIDs for the qualifying rows. How do get this?

0

2 Answers 2

7
$arrTID = $this->input->post('Present');
$atnDate = $this->input->post('atnDate');

$this->db->select('TraineeID');
$this->db->where_in('TraineeID', $arrTID);
$this->db->where('attnDate', $atnDate);
$query = $this->db->get('tbl_attendance_processed');

// and fetch result
$res = $query->result(); // as object
$res = $query->result_array(); // as array

and learn this http://www.codeigniter.com/userguide2/database/active_record.html

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

Comments

0
$array_check = array(10,11,12,13);
$name = "Raj Shekhar";

$this->db->select('*');

$this->db->where_in('id', $array_check);

$this->db->where('name', $name);

$query = $this->db->get('table_name');

// return result as array
return $query->result_array(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.