drqvsx1228 2015-11-04 13:09 采纳率: 0%
浏览 18
已采纳

php代码在codeigniter中显示文本框内的选定行数据

I have a single form for add ,view update and delete.

My page contain table with Edit and delete link.

I need when I click on edit link then it will show the selected row data inside text box.

How can I populate the selected row data and display inside a text box?

This is all in codeIgnitter.

plz see the attached screen shots here for refrence of my view The code is below:

Controller

public function edit()
{
    $id =  $this->input->get('id');
    $this->db->where('id',$id);
    $data['query'] = $this->db->get('categort_tbl');
    $data['id'] = $id;
    $this->load->view('category', $data);
}

public function select()
    {   
        $data['title'] = "Welcome to DB";
        $data['results'] = $this->category_model->getAll();
        $this->load->view('category',$data);
    }

form and list view category.php

<form name="frm1" method="post" action="<?php echo base_url(); ?>category/save">

<table height="40px">
<tr>
<td width="9%">Category :</td>
<td width="21%"><input type="text" name="category" required=""  size="40" value=""/></td>
<td width="48%"><input type="submit" class="submit_button" name="save" value="Save"/></td>
</tr>

</table>

</form>
</div>

<div id="page-wrap">
<table width="60%" border="1">
 <tr>
    <td>Category</td> 
    <td>Date</td> 
    <td colspan="2" style="text-align:center">Actions</td>    
  </tr>
  <?php if(isset($results)){ foreach($results as $row) { ?>
 <tr>    
    <td><?php echo $row->category; ?></td>
    <td><?php echo $row->created; ?></td>

    <td><?php echo anchor('category/edit?id='.$row->id,'Edit')?></td>

    <td><?php echo anchor('category/delete?del='.$row->id,'Delete',array('onclick' => "return confirm('Do you want delete this record')"))?></td>   


  </tr>
 <?php } } ?>

</table>
    </div>
  • 写回答

1条回答 默认 最新

  • douzhanhui5662 2015-11-04 13:14
    关注

    Don't Write query directly in controller. This is bad use of MVC. You can write your query in model file.

    Your code not fetching data from database

    Controller

    function edit()
    {
        $id =  $this->input->get('id');
        $this->db->where('id',$id);
        $data['data'] = $this->model_name->get_data($id);// call your model file and pass result in data variable
        $data['id'] = $id;
        $data['title'] = "Welcome to DB";
        $data['results'] = $this->category_model->getAll();
        $this->load->view('category', $data);
    }
    

    Model

    function get_data($id)
    {
         $this->db->where('id',$id);
    
         $query=$this->db->get('categort_tbl');
         return $query->row();// fetch row and return from model
     }
    

    Views

    <tr>
    <td width="9%">Category :</td>
    <td width="21%"><input type="text" name="category" required=""  size="40" value="<?php echo $data->category;?>"/></td>
    <td width="48%"><input type="submit" class="submit_button" name="save" value="Save"/></td>
    </tr>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料