CodeIgniter Forums
Passing too much information? - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived General Discussion (
+--- Thread: Passing too much information? (/thread-18908.html)

Passing too much information? - El Forum - 05-21-2009

Hi guys,

I've got a theoretical question: should I try to reduce the amount of data in my variables been passed to my view?

To explain: I have a db with lots of tables. One table is CustomerProfile. This table has approximately 12 columns of generic data about the customer (nothing secret to the customer who is logged in). Note: the user password etc is not in this table.

Now some of my views only need 2-3 columns of this data to display what I want. My question is; should I just get the whole row of the customerprofile, and pass that to my view, and just use the variables I want? Or should I write a new function in my model, to select only the columns I need, and pass that back?

I'm guessing passing everything causes more memory use on your server, while passing just the columns will cause more sql processing (cpu) (and more programming time since I need to adjust the model)?


Passing too much information? - El Forum - 05-22-2009

A quick solution to use the fastest queries and the least data using AR
function get_profiles($fields)
    if(!empty($fields){ $this->db->select($fields); }

    return $this->db->get('table')->result();

function get_profile($id,$fields='')
   if(!empty($fields){ $this->db->select($fields); }

   return $this->db->get_where('table',array('id'=>$id))->row();
It's too bad the get and get_where method don't provide this option themselves because i think there are more queries where you need to get specific fields/columns than there are getting all the fields from a table.

Passing too much information? - El Forum - 05-22-2009

In all the get functions in my models, I have an optional select parameter which defaults to everything
// The function
function get_users($select = '*') {
    $query = $this->db->get('users');
    return $query->num_rows() == 0 ? false : $query->result();

// Getting all the fields
$users = $this->user_model->get_users();

// get just their name and surname
$users = $this->user_model->get_users('first_name, last_name');