我使用下面的代碼從pr_users表中獲取ID並將其存儲在pr_notification_table中,但無法將逗號分隔的值存儲到pr_notifications表中。我想存儲$ notification_data ['show_users']作爲1,2,3,4等,以便通知發送到這些ID。其上執行此,我已附加表的圖像也插入NULL,檢索數組在codeigniter中逗號分隔值
pr_notifications表是如下:
我的控制器的代碼是:
if($data['rows'][0]['last_status'] == 'Accepted')
\t \t \t {
\t \t \t \t $ids= '22';
\t \t \t $data['success_message'] = $this->exit_common->send_notification_to_all_roles($ids);
\t \t \t echo "Success";
\t \t \t
\t \t \t }
我的型號代碼是:
function send_notification_to_all_roles($ids)
\t \t {
\t \t \t
\t \t \t global $USER;
\t \t \t $post_arr = $this->input->post();
\t \t \t $this->db->select('g.*,id');
\t \t $this->db->from('pr_users as g');
\t \t $this->db->where('userroleid', $ids);
\t \t //$this->db->join($this->myTables['pr_users_details'].' as ud','ud.userid = g.userid');
\t \t //$this->db->join('pr_users_details as ud','ud.userid = g.userids');
\t \t
\t /* \t $this->db->join($this->myTables['users_details'].' as ud','ud.userid = g.userid');
\t \t $this->db->join('pr_resignation_type as gt','gt.id = g.sr_type');*/
\t \t $query=$this->db->get(); \t
\t \t
\t \t $return \t = $query->result_array();
\t \t $arr = explode(',',$return);
\t \t foreach($arr as $num)
\t \t {
\t \t \t echo $num."<br>";
\t \t \t }
\t \t print_r($num);
\t \t die;
\t \t
\t \t \t $manager_id = $this->get_value_by_id('managerid','users',$this->session->userdata('admin_id'));
\t \t \t $user_id='1';
\t \t \t \t \t $v_memberid = $manager_id . "," . $user_id;
\t \t \t \t \t \t //$manager_id = $this->get_value_by_id('managerid','users',$this->session->userdata('admin_id'));
\t \t \t \t \t $notification_data['ref_table'] \t \t \t = \t 'pr_resignation_requests'; \t
\t \t \t \t \t $notification_data['ref_id'] \t \t \t = \t '1';
\t \t \t \t \t $notification_data['modifier_id'] \t \t = \t $USER->id;
\t \t \t \t \t $notification_data['show_users'] \t \t = \t $num;
\t \t \t \t \t $notification_data['notification_descr']= \t "A new Job has been created" ;//$manager_id;
\t \t \t \t \t $notification_data['notification_text'] \t = \t "A new Job has been created";
\t \t \t \t \t $notification_data['added_on'] \t \t \t = \t date("Y-m-d H:i:s");
\t \t \t \t \t $notification_data['url'] \t \t \t \t = \t 'exits';
\t \t \t \t \t $notification_data['uurl'] \t \t \t \t = \t 'exits';
\t \t \t \t \t $this->db->insert($this->myTables['notifications'],$notification_data);
\t \t \t \t \t return 'Resignation Request submitted successfully';
\t \t }
請檢查列數據類型並將其設置爲varchar。 –
改爲varchar \t 其插入Array Array Array Array – shank
什麼是您的print_r($ num);回報? –