2016-08-17 23 views
-1

我使用下面的代碼從pr_users表中獲取ID並將其存儲在pr_notification_table中,但無法將逗號分隔的值存儲到pr_notifications表中。我想存儲$ notification_data ['show_users']作爲1,2,3,4等,以便通知發送到這些ID。其上執行此,我已附加表的圖像也插入NULL,enter image description here檢索數組在codeigniter中逗號分隔值

pr_notifications表是如下:

enter image description here

我的控制器的代碼是:

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 }

+0

請檢查列數據類型並將其設置爲varchar。 –

+0

改爲varchar \t 其插入Array Array Array Array – shank

+0

什麼是您的print_r($ num);回報? –

回答

4

我認爲你必須從pr_users表notification_id搞定,然後使用GET notification_id逗號seprated.Assume下面的代碼比你的通知ID陣列是: - $user_notification_ids_info 現在有了這個代碼去。

$ids = ''; $notification_ids = ''; 
for($i=0; $i<count($user_notification_ids_info); $i++) 
{ 
$ids = $user_notification_ids_info[$i]['notification_id']; 
$notification_ids.= $ids.", "; 
} 
$notification_ids = substr(trim($notification_ids), 0, -1); 

現在只需echo $notification_ids;它將返回您的逗號分隔通知ID。 它可以幫助你嘗試這一個。

0

要存儲$ IDS逗號隔開?然後使用implode()。

$ arr = array('Hello','World!','Beautiful','Day!'); echo implode(「,」,$ arr);

我希望這會有所幫助。

+0

它插入陣列陣列陣列陣列 – shank