在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){
echo "$t->nama_produk";
}
我想展示的产品只有category ='Men',但是使用我的代码它会显示所有类别的产品。想法?
答案 0 :(得分:0)
试试这个。你在使用限制时错了。
$query=$this->db->query("SELECT * FROM produk WHERE id_kategori='Men' order by nama_produk ASC LIMIT $limit, $start");
答案 1 :(得分:0)
$this->db->limit($limit, $start);
$this->db->where('id_kategori', 'men');
$this->db->order_by('nama_produk');
$query = $this->db->get("produk");
希望这项工作!
用于计数:
public function record_count($limit, $start) {
$this->db->from('count(id_produk) AS count');
$this->db->where('id_kategori', 'men');
$this->db->order_by('nama_produk');
$this->db->limit($limit, $start);
$return = $query->row_array();
return $return['count'];
}
答案 2 :(得分:0)
试试这个
cotroller中的
public function get_count()
{
//count
$query=$this->db->query("SELECT * FROM produk WHERE id_kategori='Men'");
$result = $query->result_array();
$count = count($result);
return $count;
}
//data from table
public function fetch_countries($limit, $page)
{
$query=$this->db->query("SELECT * FROM produk WHERE id_kategori='Men' LIMIT $page, $limit");
$result = $query->result_array();
return $result;
}
在模型中
//to show data
<?php
foreach ($results as $new_result)
{
echo $new_result['nama_podak'];
}
?>
//to show pagination
<?php
echo $link//Page segment tabs(you can config boostarp for this)
?>
在视图中
right join