0

3つの異なるドロップダウンを持つフォームを取得しました。最初のページで正常に機能する検索結果をページ分割するというアイデアですが、2つ以上のページを取得すると、検索だけでなくデータベース全体が表示されます。

[編集]:わかりました。CIのpaginatorクラスでコードを更新しました。私はまだ同様の問題で問題を抱えています。これで正しくページが表示されますが、リンクをクリックすると、次のように表示されます。不明な列'IS NULL LIMIT 9、9' in'whereclause'

[edit2]:誰かがこれを見つけた場合に備えて、この方法を使用して問題を修正することができましたhttp://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-search-results-without-クエリ文字列-2/

これが私のコードです。

モデル:(検索結果全体を返す関数と、制限とオフセットを含む結果を返す関数の2つの関数があります)

function buscarHotel($dpto, $ciudad, $id_precio, $limit = 10, $offset = 0)
{

    $w=array();
        if (!empty($dpto)) 
        {
             $w[]="cod_ciudad IN (SELECT cod_ciudad FROM ciudad WHERE departamento_id = $dpto)"; 
        }
        if (!empty($ciudad)) 
        {
             $w[]="cod_ciudad IN (SELECT cod_ciudad FROM ciudad WHERE cod_ciudad = $ciudad)"; 
        }
        if (!empty($id_precio)) 
        {
             $w[]="des_precio_referencial IN (SELECT rango FROM preciohotel WHERE id = $id_precio)"; 
        }

    if (count($w)) $where="WHERE ".implode(' AND ',$w); else $where='';
    $query = $this->db->query("select id, nom_comercial, cod_ciudad, des_foto 
                               FROM hotel 
                               $where");
                               #ORDER BY id desc
                               #LIMIT $limit
                               #OFFSET $offset ");

    return $query->result();

}

function buscarHotelLimit($dpto, $ciudad, $id_precio, $limit)
{

    $w=array();
        if (!empty($dpto)) 
        {
             $w[]="cod_ciudad IN (SELECT cod_ciudad FROM ciudad WHERE departamento_id = $dpto)"; 
        }
        if (!empty($ciudad)) 
        {
             $w[]="cod_ciudad IN (SELECT cod_ciudad FROM ciudad WHERE cod_ciudad = $ciudad)"; 
        }
        if (!empty($id_precio)) 
        {
             $w[]="des_precio_referencial IN (SELECT rango FROM preciohotel WHERE id = $id_precio)"; 
        }

    if (count($w)) $where=implode(' AND ',$w); else $where='';
    /*$query = $this->db->query("select id, nom_comercial, cod_ciudad, des_foto 
                               FROM hotel 
                               $where");*/
                $this->db->select('id, nom_comercial, cod_ciudad, des_foto');
                $this->db->where("$where");
                $query = $this->db->get('hotel', $limit, $this->uri->segment(3));

    return $query->result();

}

コントローラ:

function buscar()
{
    $dpto = (int)$this->input->post('departamentos');
    $ciudad = (int)$this->input->post('ciudades');
    $precio = (int)$this->input->post('precios');   

    $this->load->model('mhotel');
            $this->load->model('mciudad');

            $total = (int)count($this->mbuscador->buscarHotel($dpto, $ciudad, $precio));
    $limit = 9;


    $this->load->library('pagination');

    $config['base_url'] = 'http://infohotelperu.com/buscador/buscar';
    $config['total_rows'] = $total;
    $config['per_page'] = $limit;
    $config['num_links'] = 5;

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


    $info = $this->mbuscador->buscarHotelLimit($dpto, $ciudad, $precio, $limit);        

    $results['info'] = $info;

    $this->load->view('resultados', $results);
}

そして私の見解では、私はちょうど得ました

<?php echo $this->pagination->create_links(); ?>
4

2 に答える 2

2

これが私のコントローラーからのコードです:

$this->load->model("entries");

//pagination
$this->load->library('pagination');

$config['full_tag_open'] = '<div class="full_pagination">';
$config['full_tag_close'] = '</div>';

$config['next_tag_open'] = '<span class="prev_next_pagination">';
$config['next_tag_close'] = '</span>';

$config['prev_tag_open'] = '<span class="prev_next_pagination">';
$config['prev_tag_close'] = '</span>';

$config['num_tag_open'] = '<span class="num_pagination">';
$config['num_tag_close'] = '</span>';

$config['cur_tag_open'] = '<span class="cur_pagination">';
$config['cur_tag_close'] = '</span>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Vorige';
$config['base_url'] = base_url().'index.php/blog/index';

$config['total_rows'] = $this->entries->countAll();
$config['per_page'] = 3;
$config['num_links'] = 10;

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

//end pagination config

$entries = $this->entries->get_all($config['per_page']);

$data['entries'] = $entries;
$data['titel']="Blog - Frederik";
$data['main_content']='index';
$this->load->view('includes/template', $data);

そして、これは私の見解です:

foreach($entries as $entry){
     // display entry info here
}

<div id="pagination" align="center">
    <?php echo $this->pagination->create_links(); ?>
</div>

これはうまくいくはずです!ライブラリをロードすることを忘れないでください!;)

于 2013-04-02T03:13:13.093 に答える
1

codeigniterのページネーションを使用する必要があります。チャームのように機能します;)

詳細はこちら:

http://ellislab.com/codeigniter/user-guide/libraries/pagination.html

于 2013-03-14T01:43:57.260 に答える