如何在 codeigniter 中转换 mysql_fetch_array?

how to convert mysql_fetch_array in codeigniter?

我是 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;

试试 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
    }
}    
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;