我在mysql中遇到这个问题,我有两个表,“A”和“B”
TableA:
S.No contact1 contact2 status
1 Blbh eeee 1
TAbleB:
S.No Phone1 phone2
1 ddd ssss
从这张表中我将获得价值,从TableA我要去检查
if (status == 1)
{
run tableA;
}
else
{
run table b;
}
我退出了此查询的返回结果。在视图中,如何使用受尊重的列名获取值。我不知道这一点,帮助我获得价值。
public function contDetails($id){
$check = $this->db->query("SELECT contact_status FROM account WHERE id = '$id' ");
$str = $check->row();
$chk = $str->contact_status;
if($chk == 1){
$query = $this->db->query("SELECT * FROM account WHERE id = '$id'");
}else{
$query = $this->db->query("SELECT * FROM contact_details WHERE user_id = '$id'");
}
$run = $query->num_rows();
print_r($run);
}
答案 0 :(得分:0)
您可以在模型中使用
$query = $this->db->get(); //--- run the query ---//
return $query->result() //--- to get result in array of object ---//
然后在您的视图中使用foreach循环
foreach($results as $result){
echo $result->columnName;
}
答案 1 :(得分:0)
答案 2 :(得分:0)
在您的视图中,您可以使用如下内容:
<?php
foreach($results as $result)
{
echo (isset($result['col1']))?$result['col1']:$result['col1_2'];
}
?>
并且不要忘记在控制器中使用result_array()instsead结果