dpo69086 2015-08-06 06:30
浏览 26
已采纳

如何使用codeigniter进行计数评论,

I'm working on a project. how to calculate comment by id?

example

controler:

public function comments() {

$id_alat = $this->db->where('id_alat');
$com = $this->mcrud->getComent($id_alat);
$com = $this->mcrud->getComent($id_alat);
$data = array (
                'com' => $com,
                'content' => 'instrument/instrument');
$this->load->view('layouts/wrapper', $data);
 }

models:

public function getComent($id_alat) {

$sql = "SELECT count (*) as num FROM WHERE tbcoment $id_alat tbcoment.id_alat = {}";
$this->db->query($sql);
} 

view:

comments: <?php echo $com; ?>
  • 写回答

3条回答 默认 最新

  • doucheng1891 2015-08-06 07:52
    关注

    Use following code for model

    Your Model

    public function getComent($id_alat) 
    {
        $sql = "SELECT count (*) as num FROM WHERE tbcoment.id_alat = '$id_alat'";
        $res=$this->db->query($sql)->row_object();
        return $res->num; 
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?