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