如何在codeigniter中单击userid后获取记录表单数据库?

时间:2015-10-16 08:27:21

标签: html codeigniter

我可以在点击编辑图标(铅笔图标)后从数据库中检索记录,但我得到了我在模型中写的特定ID详细信息。如果我们点击编辑图标,将打开一个弹出窗口,它将显示特定的userid records.for下面的图像如果我将点击用户ID 3,将显示记录,如果我将点击用户ID 4,将显示记录,同样在用户ID 5上。请帮助我。

提前致谢  enter image description here enter image description here

控制器

public function update_retrive()
{
$id = $this->uri->segment(3);
$this->load->model("model_add_user");
$d=$this->model_add_user->update_retrive($id);
$data['posts'] = $d;

}

模型

public function update_retrive($id)
{
$this->db->where('userId',$id);/* I have to select multiple userid but how?*/
$this->db->from('add_user');
$q = $this->db->get();
return $q->result();
}

查看

<div  class="table-responsive">
   <table class="table table-bordered" >  
        <thead>
         <tr>  


          <td><b></b></td>
          <td><b></b></td>
            <td><b>userId</b></td>  

            <td><b>firtsname</b></td>  

            <td><b>lastname</b></td>  
            <td><b>mobileno</b></td>  


            <td><b>address</b></td> 
            <td><b>city</b></td>  

            <td><b>email</b></td> 

         </tr> 
          </thead>

         <?php  
         foreach ($user->result() as $row)  
         {  
            ?>

              <tbody><tr >  



        <td><a href="<?php echo site_url('Welcome/delete/'.$row->userId)?>"><img src="http://localhost/CRM/img/delete.png" name="delete_image" ></a></td>
       <!-- <td><a href="<?php echo site_url('Welcome/update/'.$row->userId)?>"><img src="http://localhost/CRM/img/edit.png" name="edit_image" ></a></td>-->
        <td><a id="btnclick" href="<?php echo site_url('Welcome/update_retrive/'.$row->userId)?>"><img src="http://localhost/CRM/img/edit.png" name="edit_image" ></a></td>


            <td><?php echo $row->userId;?></td>  

            <td><?php echo $row->firtsname;?></td>    

            <td><?php echo $row->lastname;?></td>  
            <td><?php echo $row->mobileno;?></td>  


            <td><?php echo $row->address;?></td> 
            <td><?php echo $row->city;?></td> 

            <td><?php echo $row->email;?></td> 

            </tr>   </tbody> 
         <?php }  

         ?>  

   </table>  

   <form id="form1">

<div id="popupdiv"  style="display: none">

   <?php foreach($posts as $post){?>

    <input type="text" name="userId" placeholder="USER ID" style="width:200px" value='<?php echo $post->userId;?>'>&nbsp;


    <input type="date" name="date" style="width:200px" value='<?php echo $post->date;?>'>
    <input type="text" name="firtsname" placeholder="FIRST NAME" style="width:200px" value='<?php echo $post->firtsname;?>'>&nbsp;
    <input type="text" name="middlename" placeholder="MIDDLE NAME" style="width:200px" value='<?php echo $post->middlename;?>'>&nbsp;
    <input type="text" name="lastname" placeholder="LAST NAME" style="width:200px" value='<?php echo $post->lastname;?>'>&nbsp;

    <input type="text" name="mobileno" placeholder="ENTER MOBILE NO." style="width:200px" value='<?php echo $post->mobileno;?>'>&nbsp;
    <input type="text" name="landline" placeholder="LANDLINE No." style="width:410px" value='<?php echo $post->landline;?>'>
    <textarea name="address" placeholder="ENTER ADDRESS" style="width:410px" ><?php echo $post->address;?></textarea>

    <input type="text" name="city" placeholder="CITY" style="width:200px" value='<?php echo $post->city;?>'>&nbsp;
    <input type="text" name="locality" placeholder="LOCALITY" style="width:200px" value='<?php echo $post->locality;?>'>
    <input type="text" name="email" placeholder="ENTER EMAIL" style="width:410px" value='<?php echo $post->email;?>'></br>

  <input type="submit" class="submit" name="UPDATE" value="UPDATE" >
<?php }
         ?>
</div>

</form>

  </div>

2 个答案:

答案 0 :(得分:2)

您需要在网址中发送ID值 试试这个

<a href = "<?php echo site_url('Welcome/update_retrive');?>/<?php echo 'your id'";?>">edit</a>

在你的控制器中创建一个功能

    public function update_retrive()
    {
    $id = $this->uri->segment(3);
    $this->load->model("model_add_user");
    $d=$this->model_add_user->update_retrive($id);
    $data['posts'] = $d;
}

现在在你的模特中

public function update_retrive($id)
{

$this->db->where('userId',$id);/* I have to select multiple userid but how?*/
$this->db->from('add_user');
$q = $this->db->get();
return $q->result();
}

如果您不想在网址中发送ID您也可以使用ajax获取数据http://w3code.in/2015/09/how-to-insert-and-view-data-without-refreshing-page-using-ajax-and-jquery-in-codeigniter

答案 1 :(得分:1)

Controller:

  $id = $this->input->post('id');

   $data = array("id" => $this->input->post('id'),
                    "****" => $this->input->post('***'),
                    "*****" => $this->input->post('***'),
                    "*****" => $this->input->post('***'),
                    "*****" => $this->input->post('***')
                       );


    $this->load->model('court_page_model');
    $result = $this->court_page_model->update_id($id, $data);


Model:


 public function update_id($id, $data)
{

$this->db->where('***', $id);
$this->db->update('****', $data);
if ($this->db->affected_rows() > 0) {
        return true;

}