0

i am fresher, i have one table in database with table name of'teams' i want first_name with user_type 3 and user_type 4 separated like that first_name jon,roy with user_type 3 first_name robert,sina with user_type 4

now my problem is that there is column name is same i am unable to separate by user_type these values because of same column name (first_name)

My Database table name 'teams'

-------------------------------------
id    |  first_name    |   user_type
-------------------------------------
1        jon              3
2        roy              3
3        robert           4
4        sina             4
-------------------------------------

this is my code

model

       public function fetch_team() {
            $this->db->select('team.*');
            $this->db->from('team');
           $where = '(user.user_type="3" or user.user_type = "4")';
           $this->db->where($where);
           $query = $this->db->get();
            $result = $query->result_array();
            return $result;
        }

controller

        $value = $this->Querydata->fetch_team();
        $data['data']['teams'] = $value;

view

     <?php foreach ($data['teams'] as $key => $value) { ?>
     <tr>
      <td><input type="checkbox" id="<?php echo $value['team_id']; ?>" class="flat team_list multiple_delete"></td>

      <td><?php echo $value['id']; ?></td>
      <td><?php echo $value['first_name']; ?></td> // for user_type 3
<td><?php echo $value['first_name']; ?></td>  // for user_type 4 
    </tr>
    <? php }?>

problem statement

// for user_type 3 // for user_type 4 there at a time one $value['first_name']; ?> // for user_type 3 show another hide vise-versa

Himanshu
  • 51
  • 7
  • difficult to understand your problem – Avi Aug 17 '18 at 11:10
  • `$this->db->select('team.*);`, missing closing `'` – brombeer Aug 17 '18 at 11:15
  • sir, i want to separate first_name of column name according to its user_type but the first_name column name is same for user_type how divide first_name according to user_type (user_type) 3 for jon, roy (first_name) (user_type) 4 for robert,sina (first_name) – Himanshu Aug 17 '18 at 11:17
  • I think what you're looking for is at this link: https://stackoverflow.com/a/13451984/8121583 – adamoffat Aug 17 '18 at 11:53
  • yes Adam Moffat. i am looking like that values as us see in link, this is my upper question code is dummy code, some more issue in my fetch values there is not separating according to my user_type 3,4 values of name – Himanshu Aug 18 '18 at 01:48

1 Answers1

0

you have to check each row in your foreach statement if its user_type 3 or 4:

Try this

<?php if($value['user_type']=3) { echo "<td>".$value['first_name'].</td>"; } else { echo "<td></td>"; }?> // for user_type 3
<?php if($value['user_type']=4) { echo "<td>".$value['first_name'].</td>"; } else { echo "<td></td>"; }?> // for user_type 4

The 'if' statement checks the user type and write the name of an empty <td></td>.

burnbao
  • 1
  • 3
  • your answer is beneficial for me, sir i am unable to fetch data by same column name of first_name into 3 , 4 according to user_type – Himanshu Aug 18 '18 at 05:46