codeigniter php 事件管理系统..我想在创建事件时发出通知
codeigniter php Event management system.. I want to make notification when the event is created
您好,先生。有人可以帮我吗我正在尝试编写通知代码。事件管理系统。管理员将为学者创建活动。在创建活动的过程中,管理员将选择活动的奖学金。当管理员完成创建活动时,来自该奖学金的学者将自动收到他们的通知。我的问题是我无法将 event_id 插入到数据库中的通知 table 中。我不知道为什么我的 $this->db->insert_id() 在 $data7 中。 $data5 和 $data6 正在工作
public function create_event_scholar()
{
$now = date('Y-m-d');
$start=$_POST['start_date'];
$end=$_POST['end_date'];
if(($start==$now)||$end==$now){
$event_status= "Ongoing";
}
else if(($start < $now)&&($end>$now)){
$event_status= "Ongoing";
}
else if(($start<$now)&&($end<$now)){
$event_status= "Done";
}
else {
$event_status= "Upcoming";
}
$data = array
(
'event_id' => '',
'event_title' => $this->input->post('event_title',true),
'event_desc' => $this->input->post('event_desc',true),
'start_date' => $this->input->post("start_date",true),
'end_date' => $this->input->post("end_date",true),
/*'event_status' => $event_status,*/
'event_sponsor' => $this->input->post('event_sponsor',true),
'Semester' => $this->input->post("Semester",true),
'school_year' => $this->input->post('school_year',true),
'event_for' => 'Scholar',
'start_time' => $this->input->post('start_time',true),
'venue' => $this->input->post('venue',true),
'end_time' => $this->input->post('end_time',true),
'user_id' => $this->input->post('user_id',true),
'color ' => $this->input->post('color',true)
);
$sql1= $this->db->insert('event',$data);
$earlier = new DateTime($_POST['start_date']);
$later = new DateTime($_POST['end_date']);
$diff = $later->diff($earlier)->format("%a");
$data = array(
'security_id' => "",
'event_id' =>$this->db->insert_id(),
'scholarship' =>$this->input->post('scholarship',true),
'max_attendees' =>$this->input->post('Participants',true),
'pre_reg' =>$this->input->post('pre',true),
'total_attendance'=>$diff,
'event_duration' =>$this->input->post('event_duration',true),
);
$sql2=$this->db->insert('event_security',$data,'event_id');
$data3=array(
'assign_id' => '',
'user_id' =>$this->input->post('user_id',true),
'event_id' =>$this->db->insert_id()
);
$sql3= $this->db->insert('tbl_staff_events',$data3);
$data5 = array(
'notification_id' =>'',
'subject' =>$this->input->post('event_title',true),
'body' =>"There is an event",
'event_id' =>$this->db->insert_id()
);
$this->db->insert('notification',$data5);
$subject=$this->input->post('scholarship',true);
$this->db->select('*');
$this->db->from('tbl_scholar');
$this->db->where('scholarship_id',$subject);
$get= $this->db->get()->result_array();
foreach ($get as $value) {
$data6=array(
'participants_id' => '',
'event_id' =>$this->db->insert_id(),
'user_id' =>$value['user_id']
);
$this->db->insert('participants',$data6);
}
$data7= array(
'sent_id' =>'',
'read' =>'0',
'recieve' =>'0',
'notification_id' =>$this->db->insert_id(),
'participants_id' =>$this->db->insert_id()
);
$this->db->insert('sent_notification',$data7);
if($sql1===true && $sql2===true && $sql3 === true)
{
return true;
}
else
{
return false;
}
}
此代码可能对您有所帮助,
$sql1= $this->db->insert('event',$data);
$event_id = $this->db->insert_id();
$this->db->insert('notification',$data5);
$notification_id = $this->db->insert_id();
$this->db->insert('participants',$data6);
$participants_id = $this->db->insert_id();
$this->db->insert_id();
returns 最后执行的查询id
您好,先生。有人可以帮我吗我正在尝试编写通知代码。事件管理系统。管理员将为学者创建活动。在创建活动的过程中,管理员将选择活动的奖学金。当管理员完成创建活动时,来自该奖学金的学者将自动收到他们的通知。我的问题是我无法将 event_id 插入到数据库中的通知 table 中。我不知道为什么我的 $this->db->insert_id() 在 $data7 中。 $data5 和 $data6 正在工作
public function create_event_scholar()
{
$now = date('Y-m-d');
$start=$_POST['start_date'];
$end=$_POST['end_date'];
if(($start==$now)||$end==$now){
$event_status= "Ongoing";
}
else if(($start < $now)&&($end>$now)){
$event_status= "Ongoing";
}
else if(($start<$now)&&($end<$now)){
$event_status= "Done";
}
else {
$event_status= "Upcoming";
}
$data = array
(
'event_id' => '',
'event_title' => $this->input->post('event_title',true),
'event_desc' => $this->input->post('event_desc',true),
'start_date' => $this->input->post("start_date",true),
'end_date' => $this->input->post("end_date",true),
/*'event_status' => $event_status,*/
'event_sponsor' => $this->input->post('event_sponsor',true),
'Semester' => $this->input->post("Semester",true),
'school_year' => $this->input->post('school_year',true),
'event_for' => 'Scholar',
'start_time' => $this->input->post('start_time',true),
'venue' => $this->input->post('venue',true),
'end_time' => $this->input->post('end_time',true),
'user_id' => $this->input->post('user_id',true),
'color ' => $this->input->post('color',true)
);
$sql1= $this->db->insert('event',$data);
$earlier = new DateTime($_POST['start_date']);
$later = new DateTime($_POST['end_date']);
$diff = $later->diff($earlier)->format("%a");
$data = array(
'security_id' => "",
'event_id' =>$this->db->insert_id(),
'scholarship' =>$this->input->post('scholarship',true),
'max_attendees' =>$this->input->post('Participants',true),
'pre_reg' =>$this->input->post('pre',true),
'total_attendance'=>$diff,
'event_duration' =>$this->input->post('event_duration',true),
);
$sql2=$this->db->insert('event_security',$data,'event_id');
$data3=array(
'assign_id' => '',
'user_id' =>$this->input->post('user_id',true),
'event_id' =>$this->db->insert_id()
);
$sql3= $this->db->insert('tbl_staff_events',$data3);
$data5 = array(
'notification_id' =>'',
'subject' =>$this->input->post('event_title',true),
'body' =>"There is an event",
'event_id' =>$this->db->insert_id()
);
$this->db->insert('notification',$data5);
$subject=$this->input->post('scholarship',true);
$this->db->select('*');
$this->db->from('tbl_scholar');
$this->db->where('scholarship_id',$subject);
$get= $this->db->get()->result_array();
foreach ($get as $value) {
$data6=array(
'participants_id' => '',
'event_id' =>$this->db->insert_id(),
'user_id' =>$value['user_id']
);
$this->db->insert('participants',$data6);
}
$data7= array(
'sent_id' =>'',
'read' =>'0',
'recieve' =>'0',
'notification_id' =>$this->db->insert_id(),
'participants_id' =>$this->db->insert_id()
);
$this->db->insert('sent_notification',$data7);
if($sql1===true && $sql2===true && $sql3 === true)
{
return true;
}
else
{
return false;
}
}
此代码可能对您有所帮助,
$sql1= $this->db->insert('event',$data);
$event_id = $this->db->insert_id();
$this->db->insert('notification',$data5);
$notification_id = $this->db->insert_id();
$this->db->insert('participants',$data6);
$participants_id = $this->db->insert_id();
$this->db->insert_id();
returns 最后执行的查询id