在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;
}
在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');
}
在view / men.php
中<?php
foreach($results as $t) {
$t->nama_produk
}
<div><?php echo $links; ?></div>
我想展示的产品只有category ='Men',但在我的代码中显示所有类别的产品,这让我很困惑,请帮帮我。
答案 0 :(得分:0)
尝试使用fetch_countries()函数的代码
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