我正在尝试创建一个医院/用户系统,如果血样可用,用户可以请求特定医院。
因此,逻辑是:我将把用户、血液医院的三个ID存储在“请求”表中,稍后我将使用联接查询从其他表中获取名称。
(如果可能的话,请告诉我)
这是我的视图页面(它从“血样”表中获取数据):
<table>
<?php if(count($blood_all>0))
{ $i=0;
foreach ($blood_all as $user) {
$i++;
?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $user->btype ?></td>
<td><?php echo $user->detail?></td>
<td><?php echo $user->hospital_id?></td>
<td>
<?= anchor("Property/blood_req/{$user->id}",'Request', ['class'=>'btn btn-primary']); ?>
</td>
</tr>
<?php }
}?>
</table>
所以当用户按请求时,它会发送血表的ID(如果我是对的话)
如果用户没有登录,他/她必须登录,然后他/她可以发送请求:
请注意:我的血型表中已经有医院ID,所以我只需要存储用户ID,这样管理员就会知道哪个用户正在发送请求。
这是我的控制器:
public function blood_req($blood_id)
{
if(!$this->session->userdata('user_id'))
{
return redirect('Login/loginview_load');
}
else {
$this->load->model('Partner_model');
$data['blood']=$this->Partner_model->find_blood($blood_id);
$user =$this->session->userdata('user_id');
$user_data = array(
'blood_id' =>$this->input->post($data['id']) ,
'hospital_id' =>$this->input->post($data['hospital_id']) ,
'user_id' =>$user
);
if($this->Partner_model->req_send($user_data))
{
$this->session->set_flashdata('login','Request sent Successfully');
return redirect('Property/available');
}
else {
echo "fail";
}
}
}
这是我的模型:
public function find_blood($blood_id)
{
$q=$this->db->select('*')
->where('id',$blood_id)
->get('blood');
return $q->row();
}
public function req_send($data)
{
return $this->db->insert('request',$data);
}
当我按下请求时,它的打印“失败”,这意味着数据没有插入请求表中。