代码标记的分页错误 [英] Error in pagination of codeigniter
本文介绍了代码标记的分页错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在模型/ rci_model.php中
In model/rci_model.php
public function record_count() {
return $this->db->count_all("produk");
}
public function fetch_countries($limit, $start) {
$this->db->limit($limit, $start);
$query=$this->db->query("SELECT * FROM produk WHERE id_kategori='Men' order by nama_produk ASC");
return $query->result();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
在控制器/ sandal_clarudo.php
In controller/sandal_clarudo.php
function sandals_for_men(){
$data['seo'] = $this->rci_model->tampil_meta(22);
$this->load->view('head', $data);
$config = array();
$config["base_url"] = "http://localhost/clarudo/index.php/sandal_clarudo/sandals_for_men/";
$config["total_rows"] = $this->rci_model->record_count();
$config["per_page"] = 5;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->rci_model->
fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('men', $data);
$this->load->view('footer');
}
在视图/ men.php
In view/men.php
<?php
foreach($results as $t) {
$t->nama_produk
}
<div><?php echo $links; ?></div>
我想显示只有category ='Men'的产品,但在我的代码显示所有类别
I want to show product that has category = 'Men' only, but in my code showing all category product,it make me confused,help me please.
推荐答案
只需尝试使用此代码为您的fetch_countries()函数
Just try with this code for your fetch_countries() function
public function fetch_countries($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->query("SELECT * FROM produk WHERE id_kategori='Men' order by nama_produk ASC");
return $query->result();
}
这里发生的是你返回结果,如果可用或返回false
what happens here is you are return results if available or return false
这篇关于代码标记的分页错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文