繁体   English   中英

我想从Codeigniter中的表中获取最大ID值

[英]I want to get max id value from table in codeigniter

在模型文件中,我编写此代码:

public function maxcode() 
{
    $this->db->select (max(ClassID)+1 as ClassID)-> from ('class');
    $query=$this->db->get();
    if($query->num_rows>0)
    {
        $row = $query->row_array();
        return $row;
     } 
     echo $row['ClassID'];

}

在控制器功能我写.....此代码

public function maxcode() 
{ 

 $this->insert->maxcode(); 
}

现在我明白了您的问题所在。 您需要将此值传输到模板。 这是在页面控制器示例中完成的

$data['ClassID'] = $this->insert->maxcode();
$this->view('tenplate Name', $data);

并用于模板

<?php echo $ClassID; ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM