首页 > 解决方案 > i have same column name of first_name in database and have different user_type how to separated show in the two different column of site

问题描述

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

标签: phphtmlcodeigniter

解决方案


如果其 user_type 为 3 或 4,则必须检查 foreach 语句中的每一行:

尝试这个

<?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

'if' 语句检查用户类型并写入一个空的名称<td></td>


推荐阅读