如何连接数组元素并将它们存储在codeigniter php中的字段中
我正在为一个项目使用PHP Codeigniter,我需要连接多个字段,并创建一个名为key的新字段,该字段应存储在同一个表中。例如,如果我插入name:jack country:USA code:+691,那么我的代码应该动态地将jack-USA-691存储到我的表的键字段中。我有一个执行CRUD操作的基本模型。以下是获取新用户(分销商)的控制器代码,以及获取新用户(分销商)的模型: 控制器:如何连接数组元素并将它们存储在codeigniter php中的字段中,php,mysql,codeigniter,Php,Mysql,Codeigniter,我正在为一个项目使用PHP Codeigniter,我需要连接多个字段,并创建一个名为key的新字段,该字段应存储在同一个表中。例如,如果我插入name:jack country:USA code:+691,那么我的代码应该动态地将jack-USA-691存储到我的表的键字段中。我有一个执行CRUD操作的基本模型。以下是获取新用户(分销商)的控制器代码,以及获取新用户(分销商)的模型: 控制器: public function edit ($id = NULL) { // Fetch a
public function edit ($id = NULL)
{
// Fetch a user or set a new one
if ($id) {
$this->data['user'] = $this->reseller_m->get($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
}
else {
$this->data['user'] = $this->reseller_m->get_new();
}
// Set up the form
$rules = $this->reseller_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->reseller_m->array_from_post(array('sip_username','sip_password','key','allocation_block','name','email','password','phone','balance','user_num','address','country','created','modified','status'));
$data['password'] = $this->reseller_m->hash($data['password']);
$values=array($this->input->post('name'),$this->input->post('country'),$this->input->post('name'));
$key=implode('-',$values);
$this->db->insert('reseller',$key);
$key=$this->reseller_m->save($data, $id);
for($i=1; $i<=$data['user_num'];$i++)
{
$userdata=array('key'=>$key);
// here users is taken name of user table with retailer_id is field
$this->user_m->save($userdata,$id);
}
redirect('admin/reseller');
}
// Load the view
$this->data['subview'] = 'admin/reseller/edit';
$this->load->view('admin/_layout_main', $this->data);
}
我需要的一个解决方案是创建一个用户,获取其id并通过连接字段来更新它。我也发现它是正确的,但如何连接数组的元素呢?如何动态地做到这一点?请帮我写代码!我可以在数据库中动态存储连接的字符串吗?使用内爆()
进行concat,如下所示
$values=array($this->input->post('name'),$this->input->post('country'),$this->input->post('name'));
$key=implode('-',$value);
//output will be name-country-code
听起来像是家庭作业。内爆((数组)$object,'-');是的,但是我可以在我的表中插入它吗?在插入时,我在“字段列表”中得到了未知列“jack USA jack”,因此它将插入的值作为列名$values=array($this->input->post('name'),$this->input->post('country'),$this->input->post('name');$key=内爆('-',$value);$this->db->insert(‘经销商’,$key);我做了上述操作,得到了以下结果:(如何在表中插入值?我正在更新问题,请检查它
$values=array($this->input->post('name'),$this->input->post('country'),$this->input->post('name'));
$key=implode('-',$value);
//output will be name-country-code