我使用下面的代码从pr_users表中获取id并将其存储在pr_notification_table中,但无法将用逗号分隔的值存储到pr_notifications表中。我想将$ notification_data [' show_users']存储为1,2,3,4等,以便将通知发送到这些ID。它在执行时插入NULL,我也附加了表格图像,
pr_notifications表如下:
我的控制器代码是:
if($data['rows'][0]['last_status'] == 'Accepted')
{
$ids= '22';
$data['success_message'] = $this->exit_common->send_notification_to_all_roles($ids);
echo "Success";
}

我的型号代码是:
function send_notification_to_all_roles($ids)
{
global $USER;
$post_arr = $this->input->post();
$this->db->select('g.*,id');
$this->db->from('pr_users as g');
$this->db->where('userroleid', $ids);
//$this->db->join($this->myTables['pr_users_details'].' as ud','ud.userid = g.userid');
//$this->db->join('pr_users_details as ud','ud.userid = g.userids');
/* $this->db->join($this->myTables['users_details'].' as ud','ud.userid = g.userid');
$this->db->join('pr_resignation_type as gt','gt.id = g.sr_type');*/
$query=$this->db->get();
$return = $query->result_array();
$arr = explode(',',$return);
foreach($arr as $num)
{
echo $num."<br>";
}
print_r($num);
die;
$manager_id = $this->get_value_by_id('managerid','users',$this->session->userdata('admin_id'));
$user_id='1';
$v_memberid = $manager_id . "," . $user_id;
//$manager_id = $this->get_value_by_id('managerid','users',$this->session->userdata('admin_id'));
$notification_data['ref_table'] = 'pr_resignation_requests';
$notification_data['ref_id'] = '1';
$notification_data['modifier_id'] = $USER->id;
$notification_data['show_users'] = $num;
$notification_data['notification_descr']= "A new Job has been created" ;//$manager_id;
$notification_data['notification_text'] = "A new Job has been created";
$notification_data['added_on'] = date("Y-m-d H:i:s");
$notification_data['url'] = 'exits';
$notification_data['uurl'] = 'exits';
$this->db->insert($this->myTables['notifications'],$notification_data);
return 'Resignation Request submitted successfully';
}
&#13;
答案 0 :(得分: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。
它会帮助你尝试这个。
答案 1 :(得分:0)
你想以逗号分隔存储$ ids吗?然后使用implode()。
$ arr = array(&#39; Hello&#39;,&#39; World!&#39;,&#39; Beautiful&#39;,&#39; Day!&#39;); echo implode(&#34;,&#34;,$ arr);
我希望这会有所帮助。