 |
|
ส่งค่าจากฟอร์ม แล้วกด submit
ผมลองใช้ class pagination ที่ CI ให้มา ปรากฏว่าแบ่งได้ครับตามด้านล่าง
Code (PHP)
public function search() {
if($this->input->post('id')<>"") {
$id = $this->input->post('id');
} else {
$id = $this->uri->segment(4);
}
$keyword = $this->input->post('keyword');
$config = array();
$config["base_url"] = base_url() . "backend/programs/search/$id/$keyword";
$config["total_rows"] = $this->programs_model->search_record_count($id,$keyword);
$config["per_page"] = 1;
$config["uri_segment"] = 6;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(6)) ? $this->uri->segment(6) : 0;
$data["results"] = $this->programs_model->search_fetch_countries($id,$keyword,$config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$data['total_record'] = $config["total_rows"];
$data['getKeyword'] = $keyword;
$data['getCategories'] = $this->programs_model->getCategories($id);
$this->load->view('backend/programs/manage',$data);
}
1. หลังกดแรก *เลื่อนข้อมูลได้ปกติ
Code
http://localhost/attouroK/backend/programs/search/100010/ทดสอบ/1
2. แต่พอจะกดหน้าอื่นที่ต้องการ
Code
http://localhost/attouroK/backend/programs/search/100010/2
URL ส่วนหนึ่งหายไปครับ มันเกิดจากตรงไหน ผมทำหลายวันแล้ว งงมว๊าก
Script : Model
Code (PHP)
public function getCategories($id) {
$query = $this->db->query("select categoriesid,categories_name from categories where categoriesid='$id' ");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
/* Search */
public function search_record_count($id,$keyword) {
$this->db->like('title',$keyword);
$this->db->where('categories',$id);
$this->db->from('article');
return $this->db->count_all_results();
}
public function search_fetch_countries($id,$keyword, $limit, $start) {
$query = $this->db->query("select * from article left join user on post_by=userid where categories='$id' and title like '%$keyword%' order by id desc limit $start, $limit");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
/* Search */
รบกวนพี่ๆ ช่วยแนะนำหน่อยครับ
Tag : PHP, HTML/CSS, JavaScript, Ajax, jQuery
|
ประวัติการแก้ไข 2014-11-14 14:21:51 2014-11-14 14:22:25 2014-11-14 14:23:20
|
 |
 |
 |
 |
Date :
2014-11-14 14:21:05 |
By :
ilikeit |
View :
1044 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |