批量插入數據
本帖最后由 sola 于 2012-2-3 14:01 编辑各位哥哥姐姐們,我小白
是一個關注的功能
我ID為1
需要關注1000個人,不是用json存數據庫哈, 這個方法要怎麼寫呢?
$data=array(
'ufollow_who'=>$this->sess_user['user_id'],
'ufollow_whom'=>$this->input->post('user_ids'),
);
這樣寫貌似不行
好像要一个一个添加才行。。。 loadinger 发表于 2012-2-1 09:39 static/image/common/back.gif
好像要一个一个添加才行。。。
$this->load->model('follow_model');
$aa=$this->input->post('user_ids');
foreach($aa as $val){
$data=array(
'ufollow_who'=>$this->sess_user['user_id'],
'ufollow_whom'=>$val,
);
echo '<pre>';
print_r($data);
echo '</pre>';
$this->db->insert('user_followed',$data);
// $this->follow_model->addUserFw($data);
}
這樣貌似不行 for循环,记得用事务啊,一旦失败就回滚。 ci_phper_mj 发表于 2012-2-1 10:43 static/image/common/back.gif
for循环,记得用事务啊,一旦失败就回滚。
OK 搞定了 嘻嘻,哈哈 謝謝 不用FOR循環,直接 用foreac就京行了 其实mysql有一次insert多条数据的语法。其他数据好像没的。
页:
[1]