我想在 codeigniter 中使用点燃的数据表显示一些基于数据库值的值
I want to show some value based on database value using ignited datatable in codeigniter
在这段代码中,我将从数据库中获取值 1 或 0 的状态。如果状态值为一,我想显示活动,否则 inactive.Anybody 知道吗?
控制器
public function datatable() {
$this->datatables
->select("prd_id,prd_name,status")
->from('jil_products')
->edit_column('status', '', $this->custom_status('status'));
echo $this->datatables->generate();
}
我为此做了回调
function custom_status($val)
{
return ($val == 1) ? 'Active' : 'Inactive';
}
但如果值为 1,则始终 return '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();
}
在这段代码中,我将从数据库中获取值 1 或 0 的状态。如果状态值为一,我想显示活动,否则 inactive.Anybody 知道吗?
控制器
public function datatable() {
$this->datatables
->select("prd_id,prd_name,status")
->from('jil_products')
->edit_column('status', '', $this->custom_status('status'));
echo $this->datatables->generate();
}
我为此做了回调
function custom_status($val)
{
return ($val == 1) ? 'Active' : 'Inactive';
}
但如果值为 1,则始终 return '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();
}