drqvsx1228
2015-11-04 13:09
浏览 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>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题