[eluser]Unknown[/eluser]
Code:
function get_product($options=array())
{
$this->db->select("t_product.product_id as product_id",false);
//define what to show
if(isset($options['qty_purchased']))
{
$this->db->select("(prd_suggested_retail_price*".$options['qty_purchased'].") as subtotal",false);
}
if(isset($options['get_supplier']))
{
$this->db->join("t_supplier","t_product.supplier_id=t_supplier.supplier_id");
$this->db->select("sup_name");
$this->db->select("sup_description");
}
if(isset($options['get_publisher']))
{
$this->db->join("t_publisher","t_product.publisher_id=t_supplier.publisher_id");
$this->db->select("sup_name");
$this->db->select("sup_description");
}
if(isset($options['get_voucher']))
{
$this->db->join("t_voucher","t_voucher.product_id=t_product.product_id");
$this->db->select("voucher_id");
}
if(isset($options['get_seller']))
{
$this->db->join("t_seller_price","t_seller_price.product_id=t_product.product_id");
$this->db->select("seller_user_id");
}
$this->db->from("t_product");
if(isset($options['some_selection_thing']))
{
$this->db->where('some rules');
}
//----------and other selection criteria
I have this code written in my current model.....but someone suggest me to break this model down into several functions....rather than using a parameterized function like my current one.
I used this kind of function because I only need to access one function and make sure that only one query is executed everytime.....
Need opinion.....Thank you very much to all of you....