【问题标题】:I want to show some value based on database value using ignited datatable in codeigniter我想在codeigniter中使用点燃的数据表显示一些基于数据库值的值
【发布时间】:2016-02-26 06:23:44
【问题描述】:

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

控制器

     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'。我不知道为什么

【问题讨论】:

    标签: codeigniter datatables codeigniter-2 codeigniter-3


    【解决方案1】:

    试试这个:

     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 并且必须显示 active,inactive,suspend.then hw 会更改代码吗?
    • 你能推荐任何教程或页面来研究更多关于 codeigniter 中点燃数据表的信息吗??
    • @Angel 你必须更多地学习 SQL 并尝试在 codeigniter 活动模式结构中实现..
    • 我知道 sql,但我不知道它是如何转换成点燃的表查询的。
    • 所以学习主动模式法。见link
    猜你喜欢
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    相关资源
    最近更新 更多