mysql - How to merge two rows and get single array in Codeigniter/PHP? -
i working on codeigniter assigning multiple roles single user. have created table following values.
array ( [id] => 1 [store_address_id] => [customer_ref_id] => 193 [role_ref_id] => 1 [email_alert] => 0 [sms_alert] => 0 [admin_view] => 0 [admin_save] => 0 [admin_delete] => 0 [master_view] => 1 [master_save] => 1 [master_delete] => 1 [business_view] => 0 [business_save] => 0 [business_delete] => 0 [analytics_view] => 1 [analytics_delete] => 1 [analytics_save] => 1 [promotion_view] => 1 [promotion_save] => 1 [promotion_delete] => 1 )
but, in database having multiple rows need value validation
+----+----+----+ | i/p|i/p | o/p| +----+----+----+ | 0 | 0 | 0 | +----+----+----+ | 1 | 1 | 1 | +----+----+----+ | 1 | 0 | 1 | +----+----+----+ | 0 | 1 | 1 | +----+----+----+
my table this
i need validate , fetch single array.
following comment thought suggest in controller:
// set permissions array , set default values of 0 $permissions = array( 'email_alert' => 0, 'sms_alert' => 0, 'admin_view' => 0, 'admin_save' => 0, 'admin_delete' => 0, 'master_view' => 0, 'master_save' => 0, 'master_delete' => 0, 'business_view' => 0, 'business_save' => 0, 'business_delete' => 0, 'analytics_view' => 0, 'analytics_delete' => 0, 'analytics_save' => 0, 'promotion_view' => 0, 'promotion_save' => 0, 'promotion_delete' => 0, ); // rows foreach ($results $row) { // each col name , value foreach ($row $key => $value) { // make sure value needed permissions array if(isset($permissions[$key])) { // value permissions value, 1 if ($value == 1) { // set permissions array 1 $permissions[$key] = 1; } } } }
this me typing out, have not tested , there may typo's. hope helps. there may more efficient ways if dealing few rows fine.
Comments
Post a Comment