2012-10-30 34 views
1

您好,我在CI中搜索时出现问题。在第一页中,结果显示正常,但在第二页上显示1064 SQL错误。带分页错误的Codeigniter搜索

您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以找到正确的语法,以便在第1行使用AND cpt_echip.cpt_echip_nr_inventar LIKE'%%'LIMIT 10,10'

下面是代码(使用的函数):

MODEL:

function search($start, $limit){ 
     $match = $this->input->post('search'); 
     $tip_echip = $this->input->post('cpt_tip_echip_nume'); 
     $q = $this->db->query("SELECT * FROM (cpt_echip)LEFT OUTER JOIN cpt_utl ON cpt_utl.cpt_utl_marca = cpt_echip.cpt_utl_marca WHERE cpt_echip.cpt_tip_echip_id = $tip_echip AND cpt_echip.cpt_echip_nr_inventar LIKE '%$match%' LIMIT $start , $limit"); 


     $rezultat = $q->result(); 

     return $rezultat; 
    } 

function num_filter(){ 
     $tip_echip = $this->input->post('cpt_tip_echip_nume'); 
     $this->db->where('cpt_tip_echip_id', $tip_echip); 
     $q = $this->db->get('cpt_echip'); 
     $number = $q->num_rows(); 

     return $number; 
    } 

控制器:

function search(){ 

     $data = $this->helpdesk_model->general(); 

     $start_row = $this->uri->segment(3); 
     $per_page = 10; 

     if(trim($start_row) == ""){ 
      $start_row = 0; 
     } 

     $config['base_url'] = base_url() . '/index.php/helpdesk/search/'; 

     $config['total_rows'] = $this->helpdesk_model->num_filter(); 
     $config['per_page'] = $per_page; 
     $config['num_links'] = 10; 
     $config['first_link'] = 'Prima pagina'; 
     $config['last_link'] = 'Ultima pagina'; 

     $this->pagination->initialize($config); 

     $data['pagini'] = $this->pagination->create_links(); 
     $data['query'] = $this->helpdesk_model->search($start_row, $per_page); 

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

VIEW:

<table border="1"> 
      <tr> 
       <th>Nr. Inventar</th> 
       <th>Nume</th> 
       <th>Utilizator</th> 
      </tr> 
      <?php foreach($query as $row): ?> 
      <tr> 
       <td><?php echo anchor('helpdesk/detalii_echipament/'.$row->cpt_echip_nr_inventar, $row->cpt_echip_nr_inventar, array('data-fancybox-type'=>'iframe', 'class'=>'fancybox')); ?></td> 
       <td><?php echo $row->cpt_echip_nume; ?></td> 
       <td><?php echo $row->cpt_utl_nume; ?></td> 
      </tr> 
      <?php endforeach; ?> 
     </table> 
     <?php echo $pagini; ?> 

没有搜索和过滤器,分页工作正常。

回答

0

这意味着$ _POST数组是空的。当您使用指向第二页的链接进行导航时,不会有任何内容发布。您可以通过网址传递搜索数据或在第一次提交时将其存储在会话中并使用它。

只需使用print_r($ _ POST)查看,看看有什么$ _POST数组。