2016-12-09 4 views
1

PHPとブートストラップを使用してcodeigniterでページテーブルを作成しようとしています。限り、私はブラウザで自分のコードを実行したいと思う私はタイトルに登録されているエラーに直面しています。誰かが私を助けることができれば、私はとても楽しくて、感謝しています。ここに私のコードです。エラー番号:1052.フィールドリストの 'id'列が曖昧です

<!DOCTYPE html> 
<html> 
<head> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>PHP CodeIgniter Pagination with Bootstrap Styles | Example</title> 
    <!--link the bootstrap css file--> 
    <link rel="stylesheet" href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>"> 
</head> 
<body> 
<div class="container"> 
    <div class="row"> 
     <div class="col-md-12"> 
      <table class="table table-striped table-hover"> 
       <thead> 
        <tr> 
         <th>#</th> 
         <th>Employee ID</th> 
         <th>Employee Number</th> 
         <th>Employee Name</th> 
         <th>Employee Surname</th> 
         <th>Employee Address</th> 
         <th>Employee Email</th> 
        </tr> 
       </thead> 
       <tbody> 
        <?php for ($i = 0; $i < count($emplist); ++$i) { ?> 
        <tr> 
         <td><?php echo ($page+$i+1); ?></td> 
         <td><?php echo $emplist[$i]->id; ?></td> 
         <td><?php echo $emplist[$i]->employee_emer; ?></td> 
         <td><?php echo $emplist[$i]->mbiemer; ?></td> 
         <td><?php echo $emplist[$i]->adresa; ?></td> 
         <td><?php echo $emplist[$i]->email; ?></td> 
         <td><?php echo $emplist[$i]->department_emer; ?></td> 
        </tr> 
        <?php } ?> 
       </tbody> 
      </table> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="col-md-12 text-center"> 
      <?php echo $pagination; ?> 
     </div> 
    </div> 
</div> 
</body> 
</html> 

employees_view.php

employees_model.php

<?php 
class employees_model extends CI_Model{ 
    function __construct() 
    { 
     // Call the Model constructor 
     parent::__construct(); 
    } 

    //fetch department details from database 
    function get_employees_list($limit, $start) 
    { 
     $sql = 'select (id, employee_emer, mbiemer, adresa, email), department_emer from employee, department where department.id = employee.id_departament order by employee_emer limit ' . $start . ', ' . $limit; 
     $query = $this->db->query($sql); 
     return $query->result(); 
    } 
} 
?> 

employees.php

<?php 
class employees extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper('url'); 
     $this->load->database(); 
     $this->load->library('pagination'); 

     //load the department_model 
     $this->load->model('employees_model'); 
    } 

    public function index() 
    { 
     //pagination settings 
     $config['base_url'] = site_url('employees/index'); 
     $config['total_rows'] = $this->db->count_all('employee'); 
     $config['per_page'] = "5"; 
     $config["uri_segment"] = 3; 
     $choice = $config["total_rows"]/$config["per_page"]; 
     $config["num_links"] = floor($choice); 

     //config for bootstrap pagination class integration 
     $config['full_tag_open'] = '<ul class="pagination">'; 
     $config['full_tag_close'] = '</ul>'; 
     $config['first_link'] = false; 
     $config['last_link'] = false; 
     $config['first_tag_open'] = '<li>'; 
     $config['first_tag_close'] = '</li>'; 
     $config['prev_link'] = '&laquo'; 
     $config['prev_tag_open'] = '<li class="prev">'; 
     $config['prev_tag_close'] = '</li>'; 
     $config['next_link'] = '&raquo'; 
     $config['next_tag_open'] = '<li>'; 
     $config['next_tag_close'] = '</li>'; 
     $config['last_tag_open'] = '<li>'; 
     $config['last_tag_close'] = '</li>'; 
     $config['cur_tag_open'] = '<li class="active"><a href="#">'; 
     $config['cur_tag_close'] = '</a></li>'; 
     $config['num_tag_open'] = '<li>'; 
     $config['num_tag_close'] = '</li>'; 

     $this->pagination->initialize($config); 
     $data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 

     //call the model function to get the department data 
     $data['emplist'] = $this->employees_model->get_employees_list($config["per_page"], $data['page']);   

     $data['pagination'] = $this->pagination->create_links(); 

     //load the department_view 
     $this->load->view('employees_view',$data); 
    } 
} 
?> 

私を助けてください。前もって感謝します!

+0

を確認し、私はあなたの選択クエリからそれらの括弧を削除したいです。また、あなたのスペルをチェックして、あなたの参加のスペルが間違っているように見えます。最後に、正しい結合構文を使用し始めます。そこに古い古いクエリスタイルが使用されています。 –

+0

ありがとうございます。出来た。 – Lilly

答えて

0

テーブル名のエイリアスを試してください。この

  $sql = ' select employee.id, employee_emer, mbiemer, adresa, email, department_emer from employee, department 
      where department.id = employee.id_departament order by employee_emer limit ' . $start . ', ' . $limit; 

それとも

  $sql = ' select e.id, employee_emer, mbiemer, adresa, email, department_emer 
      from employee e inner join department d on d.department.id = e.id_departament 
      order by employee_emer limit ' . $start . ', ' . $limit; 
+0

私はこれを試してみましたが、私は別のエラーました: – Lilly

+0

エラー番号:1241 オペランドが1列(複数可) が含まれている必要がありますが(employee.id、employee_emer、mbiemer、adresa、電子メール)、従業員からのdepartment_emer、部門の部門を選択します。 id = employee.id_departament order by employee_emer limit 0、5 – Lilly

+0

私は2つの異なるバージョンを試しましたが、上記のエラーが表示されました – Lilly

関連する問題