[eluser]behnampmdg3[/eluser]
Hi;
I send an array of data to model to build the query nice and easy like this:
Code:
public function results_products_prev($data, $record_start=0,$number_of_records=50)
{
$this->db->select('id');
$this->db->from('products_table USE INDEX (PRIMARY)');
$this->db->join('products_status', 'products_status.id = products_table.status');
$this->db->order_by('products_table.id DESC');
$this->db->where('products_table.id <', $record_start);
$this->db->where($data);
$this->db->limit($number_of_records);
$query = $this->db->get();
return $query->result_array();
}
Now in different queries where I cant (or choose not to) use Active Records, what would be the best way to build the query dynamically based on the $data?
For exmple $data may or may not contain
id or
status columns in the WHERE condition.Something is telling me I might need to have multiple queries OR have logic in my model? Or can I just produce all the conditions below with 1 query?
Code:
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
Code:
$sql = "SELECT * FROM some_table WHERE status = ? AND author = ?";
Code:
$sql = "SELECT * FROM some_table WHERE id = ? AND author = ?";
Thank you forum