php - How to clear $this to insert more records in CodeIgniter? -
with ci, want insert 1 record in user table , 1 in post table. below brief of code (two tables have multiple columns, , use 1 example).
$this->username=$user; $this->db->insert('user',$this); $this->title='my first post'; $this->db->insert('post', $this);
however, second insert "insert post (user, title) values ('$user', 'my first post'). , error reported unknown column user in post.
how can clear members in $this before inserting next records (in table)?
this happening becouse of
$this->username=$user;
you need use
$this->db->insert('post', $this->title);
and before insert, set in title want, not
$this->db->insert('post', $this);
however if still want work object, more information how can find here, http://ellislab.com/codeigniter/user-guide/database/active_record.html#insert
Comments
Post a Comment