如何在codeigniter中转换mysql_fetch_array?

时间:2016-09-22 09:06:21

标签: codeigniter-3

我是Codeigniter的新手,我在使用mysql_fetch数组的codeigniter中创建模型时遇到问题。我不知道如何在codeigniter中转换mysql_fetch_array?

我的模特:

$auto=mysql_query("select * from penjualan order by nonota desc limit 1");
$no=mysql_fetch_array($auto);
$angka=$no['nonota']+1;

2 个答案:

答案 0 :(得分:4)

尝试使用CodeIgniters查询构建器,确实有很好的文档here 对于您的示例,我建议如下:

$query = $this->db->order_by('nonota', 'DESC')
    ->limit(1)
    ->get('penjualan');
if( $query->num_rows() > 0) {
    $result = $query->result(); //or $query->result_array() to get an array
    foreach( $result as $row )
    {
         //access columns as $row->column_name
    }
}    

答案 1 :(得分:0)

try this

$auto=$this->db->select('*')
               ->order_by('nonota','desc')
               ->limit(1)
               ->get('penjualan ');
$no    = $auto->result_array();
$angka = $no[0]['nonota']+1;//for first element in the array index 0;