Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在codeigniter中使用ignited datatable显示一些基于数据库值的值_Codeigniter_Datatables_Codeigniter 2_Codeigniter 3 - Fatal编程技术网

我想在codeigniter中使用ignited datatable显示一些基于数据库值的值

我想在codeigniter中使用ignited datatable显示一些基于数据库值的值,codeigniter,datatables,codeigniter-2,codeigniter-3,Codeigniter,Datatables,Codeigniter 2,Codeigniter 3,在这段代码中,我将从数据库中获取状态值1或0。如果状态值为1,我想显示active,否则显示inactive。有人知道吗 控制器 public function datatable() { $this->datatables ->select("prd_id,prd_name,status") ->from('jil_products') ->edi

在这段代码中,我将从数据库中获取状态值1或0。如果状态值为1,我想显示active,否则显示inactive。有人知道吗

控制器

     public function datatable() {

            $this->datatables
                    ->select("prd_id,prd_name,status")
                    ->from('jil_products')   
 ->edit_column('status', '$1', $this->custom_status('status'));

            echo $this->datatables->generate();
        } 
我没有为此回电话

function custom_status($val)
{
   return ($val == 1) ? 'Active' : 'Inactive';

}
但如果值为1,则始终返回“Inactive”。我不知道为什么

试试这个:

 public function datatable() {
/* Option 1 when you have 2 option */   
$this->datatables
    ->select("prd_id,prd_name,IF(status = '1', 'Active', 'Inactive') as status")
    ->from('jil_products');
 /* Option 2 when you have more then 2 option */   
   $this->datatables
    ->select("prd_id,prd_name, 
    case jil_products.status
    when '1' then 'Active'
    when '2' then 'Inactive'
    when '3' then 'Suspended'
    end as status
   ")
    ->from('jil_products');
   echo $this->datatables->generate();
 }

我有一个疑问。如果status的值为1、2、3和hav,以显示active、inactive和suspend。那么hw将更改代码?您是否可以建议任何教程或页面来研究codeigniter中点燃的数据表???@Angel您必须进一步学习SQL,并尝试在codeigniter活动模式结构中实现..i knw SQL,但我不知道它是如何转换为点燃表查询的,所以要学习主动模式方法。看见