php - 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
解决方案
如果其 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>
。
推荐阅读
- java - Java sql delete 语句对=有效,对in()无效?
- powershell - 使用 PowerShell 中的注册表项获取安装的软件,某些软件名称未显示
- azure - Azure 容器服务 (AKS) kubeconfig 文件已过时
- javascript - jQuery - 将点击功能分配给单选输入
- python - conda 上的 pycafe 安装在 MacBook Air Catalina 中失败
- django-models - 如何在 django rest 框架的序列化程序中添加检查约束验证器?
- r - 计算 Quanteda 语料库中每个文档中的某些字母
- c# - Azure Function App Project 的 Visual Studio Code (Windows OS) 中的 C# 未显示触发器列表
- laravel - Laravel 中的 Excel 验证
- functional-programming - 球拍:将字符串替换应用于列表