Welcome Guest, Not a member yet? Register   Sign In
query to collect columns
#1

[eluser]Bigil Michael[/eluser]
I would like to select the columns which have value 1.

table

id user_id demo1 demo2 demo3 demo4 demo5 demo6 ....................................................
1 15 1 0 0 1 0 1 ......................................
2 18 0 0 1 0 0 1 ..........................................


i want the output like this.


for user_id 15 : demo1 demo4 demo6
'' 18 : demo3 demo6


Can any one help me??

thanks in advance.....


#2

[eluser]TheFuzzy0ne[/eluser]
Can you me more specific? Is your output a string, or does that represent an array/object?

You can just grab the rows you want, and then loop through them, to put them in the format you want them to be in. It should be very simple to achieve.
#3

[eluser]Bigil Michael[/eluser]
solved this by using array.

selected the particular row, then filtered the columns to an array , where column value=1

Code:
$privilege_id = $this->Demo_model->select_privileges($id);

  $ss = array();
  foreach($privilege_id as $key => $value) {
   if (($key != 'id') && ($key != 'user_id')) {
    if($value == 1) {
     $ss[] = $key;
    }
   }  
  }




Theme © iAndrew 2016 - Forum software by © MyBB