单击下拉列表后记录从数据库中获取并在codeigniter中的文本框中显示

时间:2015-10-16 15:53:02

标签: html codeigniter

你们所有人都在做伟大的工作真的很感激。我在codeigniter中遇到问题,在点击下拉列表并在文本框中显示后从数据库中获取数据。我上传了下面的图片,以便更好地理解我的问题。在图像中我必须选择单个而不是从数据库中获取记录,同样在多个上思考。我在codeigniter中不是很好。请帮助我。enter image description here

控制器

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->model('model_Details');
        $results = $this->model_Details->retrive1();
        $data['posts'] = $results;

        $this->load->view('organization',$data );       
    }

模型

class Model_Details extends CI_Model{

public function __construct()
        {
            parent:: __construct();
            $this->load->database();

        }


public function retrive1()
{


$this->db->select('Fname,Lname,age,mobile');

$this->db->where('Id', '1');
$this->db->from('details');
$q = $this->db->get();
return $q->result();
}

查看

<div class="container">
      <div class="row">

    <div class="col-xs-2 col-sm-2 col-md-2">
    <div class="title">
  <p><strong>Website</strong></p>
  <select  style="width:150px;" name="website" >
    <option>Select</option>
    <option >Single </option>

  <option>Multiple </option>
</select>

  </div>
</div>


    <div class="col-xs-2 col-sm-2 col-md-2">
    <div class="title">

  <p><strong>Fname</strong></p>



<input type="text" name="Fname" style="width:100px;" value=''>


  </div>
</div>



    <div class="col-xs-2 col-sm-2 col-md-2">
    <div class="title">
  <p><strong>Lname</strong></p>

   <input type="text" name="Lname" style="width:100px;" value=''>

  </div>
</div>

<div class="col-xs-2 col-sm-2 col-md-2">
    <div class="title">
  <p><strong>age</strong></p>



   <input type="text" name="age" style="width:100px;" value=''>


  </div>
</div>

<div class="col-xs-2 col-sm-2 col-md-2">
    <div class="title">
  <p><strong>mobile</strong></p>
   <input type="text" name="mobile" style="width:100px;" value=''>

  </div>
</div>


</div><!--row-->
</div><!--container-->
</br></br>
<input type="submit" class="submit" name="SUBMIT" value="Submit">


  [1]: http://i.stack.imgur.com/ojjEb.png

1 个答案:

答案 0 :(得分:0)

Controller:

class Welcome extends CI_Controller 
{
  public function index()
  {
    $name = $this->input->post('website');
    $condition = "name =" . "'" . $name . "'";  

    // get person details
    $this->db->select('*');
    $this->db->from('details');
    $this->db->where($condition);

    $data['result'] = $this->db->get();
    $this->load->view('organization','refresh',$data );       
  }



View:


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

  <div class="col-xs-2 col-sm-2 col-md-2">
    <div class="title">

     <p><strong>Fname</strong></p>

  <input type="text" name="Fname" style="width:100px;" value='<?=$row->f_name; ?>'>
    </div>
  </div>

  <div class="col-xs-2 col-sm-2 col-md-2">
    <div class="title">
      <p><strong>Lname</strong></p>

      <input type="text" name="Lname" style="width:100px;" value='<?=$row->l_name; ?>'>

    </div>
  </div>

  <?php endforeach;?>