0

I am using the below code to get the ids from the pr_users table and store it in pr_notification_table,but unable to store the values separated by comma into pr_notifications table. I want to store $notification_data['show_users'] as 1,2,3,4 etc so that notifications are sent to these ids. Its inserting NULL on executing this , I have attached table images also,enter image description here

pr_notifications table is as below:

enter image description here

My controller code is:

if($data['rows'][0]['last_status'] == 'Accepted')
			{
				$ids= '22';
			$data['success_message'] = $this->exit_common->send_notification_to_all_roles($ids);
			echo "Success";
			
			}

My model code is:

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';
		}

4
  • please check the column datatype and set it as varchar. Commented Aug 17, 2016 at 10:58
  • changed to varchar its inserting Array Array Array Array Commented Aug 17, 2016 at 11:04
  • what is your print_r($num); returns? Commented Aug 17, 2016 at 11:10
  • changed code to $return = $query->result_array(); $insert = implode(" ",$return); print_r($insert); die; and its printing Array Array Array Array Commented Aug 17, 2016 at 11:13

2 Answers 2

4

I think you have to get notification_id from pr_users table, and then use the following code for get notification_id comma seprated.Assume than your notification id array is :- $user_notification_ids_info Now go with this code.

$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);

Now simply echo $notification_ids; it will return your comma seprated notification id. It will helps you try this one.

Sign up to request clarification or add additional context in comments.

Comments

0

You want to store $ids comma separated? then use implode().

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

I hope this will help.

1 Comment

its inserting Array Array Array Array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.