|
function searchs($offset='')
{
$this->load->library('pagination'); // loading pagination
$config['base_url'] = base_url()."gf/searchs"; //路徑位置
$config['per_page'] = '15'; // 每頁15筆
$config['full_tag_open'] = '<div id = "page_nav">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = '首頁';
$config['last_link'] = '末頁';
$config['next_link'] = '下一頁>';
$config['prev_link'] = '<上一頁'; // << 1 2 3 4 5 > >> 上下頁碼
$config['uri_segment'] = '3';
$devices = $this->input->get('devices');
$foodname = $this->input->get('foodname');
$this->input->set_cookie($devices,$foodname);
$this->input->cookie('foodname', TRUE);
$this->db->start_cache(); // 開始做快取
$this->db->select('*');
$this->db->from('abc');
$this->db->order_by("ID","ASC"); // 排序
if($devices == 0 && $foodname != null) // $devices 改成 0
{
$this->db->like('NAME',"$foodname");
//$query = $this->db->get(); // get() 在判斷後,判斷僅針對SQL條件
}
else if($devices != 0 && $foodname == null)
{
$this->db->where('class',"$devices");
//$query = $this->db->get();
}
else if($devices!=0 && $foodname!=null)
{
$this->db->like('NAME',"$foodname");
$this->db->where('class',"$devices");
//$query = $this->db->get();
}
$this->db->stop_cache(); // 停止快取
$query = $this->db->get(); // 抓取全部資料
$config['total_rows'] = $query->num_rows(); // 全部資料行數
echo $query->num_rows();
$this->pagination->initialize($config); // 設定完成
$this->db->limit($config['per_page'],$offset); // 疊加SQL指令 : 出現行數(15行)
$query_data = $this->db->get(); // 要輸出在畫面上的資料
echo $this->pagination->create_links(); // 產生分頁條
echo "<table border=2>";
echo "<th>".'食材名稱'."<th>".'熱量'."<th>".'水分'."<th>".'備註'."</tr>";
echo $foodname;
foreach ($query_data->result() as $row)
{
echo "<td>".$row->NAME."</td>";
echo "<td>".$row->heat."</td>";
echo "<td>".$row->water."</td>";
echo "<td>"
?>
<a href="gf/detail/<?php echo($row->ID)?>" target="_blank">查看更多</a>
<?php
echo "</tr>";
}
$call_arr = array('type' => $devices , 'f_name' => $foodname);
$this->load->view('gf_page' , $call_arr);
}
以上是我的程式碼
我在搜尋欄輸入完需求之後
第一頁是跑得出來的
但是點選第二頁之後,我取不到我一開始的值,筆數也完全不正確,再點選回上一頁筆數也是完全亂掉。
第一次發文多多指教...
|
|