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

[eluser]victorche[/eluser]
Please, give me an advice on this one. I am creating a really simple MY_Model.php with basic CRUD functions (I know there are some really good ones, but I can not use them, because I have to change a lots of code).

And because I have a lots of similar functions, I've decided to combine them. I've checked some really good pieces of code, but all those MY_Model classes suggest that the primary key is always `id`. My case is not like this. All my tables have different column names for `id`. For example... My `posts` table has `post_id` as a primary key. Table `users` has `user_id` and so on.

Instead of this:
Code:
public function edit_post($values, $post_id)
{
  $this->db->update('posts', $values, array('post_id' => $post_id));
  return TRUE;
}

public function edit_user($values, $user_id)
{
  $this->db->update('users', $values, array('user_id' => $user_id));
  return TRUE;
}
I want to combine those like:
Code:
public function edit_record($table, $values, $id)
{
  //
}

So, how to create a simple update function, when my column name is always different? Is there a way to get the primary key column?


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