【问题标题】:Codeigniter search with pagination error带有分页错误的 Codeigniter 搜索
【发布时间】:2012-10-30 13:39:27
【问题描述】:

您好,我在 CI 中的搜索有问题。在第一页显示结果正常,但在第二页显示 1064 SQL 错误。

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

这里是代码(用到的函数):

型号:

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);
    }

查看:

<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; ?>

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

【问题讨论】:

    标签: codeigniter-2


    【解决方案1】:

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

    只需使用 print_r($_POST) 检查 $_POST 数组。

    【讨论】:

      猜你喜欢
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-15
      • 2012-05-15
      • 1970-01-01
      • 2012-04-27
      相关资源
      最近更新 更多