Welcome Guest, Not a member yet? Register   Sign In
Basic MY_Model question. Need some help
#9

[eluser]PhilTem[/eluser]
You might want to set the function header to

Code:
function all_records($table, $where = array(), $field = NULL, $order = NULL)

and then maybe something like

Code:
if ( is_array($where) && count($where) )
{
    // This is easier for your and does the same as your code above did since the
    // db->where method supports associative arrays
    $this->db->where();
}
// If $where is a string we just assume that it is the field we want to order
// by. Since you define your API, you can define it anyway you want ;)
elseif ( is_string($where) )
{
    // We just shift all arguments left by one (i.e. $where is now $field,
    // $order is now $field)
    $field = $where;
    // Just to ensure we have an "ASC" or "DESC" ordering and not something invalid
    $order = strtoupper($field) == ("ASC" OR "DESC") ? : "ASC";
}

// Now just process the code as you did above since the arguments are assigned to
// the right variables
if ( $field && $order )
{
    // Again just to ensure we have an "ASC" or "DESC" ordering and not something
    // invalid
    $order = strtoupper($order) == ("ASC" OR "DESC") ? : "ASC";
    
    $this->db->order_by($field, $order);
}

// The rest of your code goes here (select from and get)


Messages In This Thread
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 02:19 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:06 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:11 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:14 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:18 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:35 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 04:36 PM
Basic MY_Model question. Need some help - by El Forum - 06-03-2012, 05:23 AM
Basic MY_Model question. Need some help - by El Forum - 06-03-2012, 06:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB