Php codeigniter:按ID从数据库获取数据

Php codeigniter:按ID从数据库获取数据,php,codeigniter-3,Php,Codeigniter 3,我的型号 <?php defined ('BASEPATH') OR exit ('No direct script access allowed'); class Agrivest_model extends CI_Model{ public function __construct(){ parent:: __construct(); $this->load->database(); } public function get_cate

我的型号

<?php

defined ('BASEPATH') OR exit ('No direct script access allowed');

class Agrivest_model extends CI_Model{ 

public function __construct(){
    parent:: __construct();
    $this->load->database();       
}
public function get_category_tb(){
  $this->db->from('category_tb');
  $this->db->limit(1);
   $query=$this->db->get();
   return $query->result();
}
我的观点

<?php foreach ($category_tb as $post){?>
<p class="category_description"><?php echo $post->category_description; ?> </p>

试试这个

public function index($cat_id){
  $data['category_tb'] = $this->agrivest_model->get_category_tb($cat_id);
  $this->load->view('landing_page', $data);
}

public function get_category_tb($cat_id){
   $query=$this->db->get_where('category_tb', array('id' => $cat_id), 1, 1);
   return $query->result();
}
不要忘记在url中传递参数category\u id

public function index($cat_id){
  $data['category_tb'] = $this->agrivest_model->get_category_tb($cat_id);
  $this->load->view('landing_page', $data);
}

public function get_category_tb($cat_id){
   $query=$this->db->get_where('category_tb', array('id' => $cat_id), 1, 1);
   return $query->result();
}

别忘了在url中传递参数category_id

但是在传递IDB的位置传递id