如何从以下查询中获取id的值
$id = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."';");
答案 0 :(得分:4)
尝试:
$row = $id->row();
echo $row->id;
答案 1 :(得分:2)
要从选择查询中回显id
,请使用->row()
$query = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."'");
$id = $query->row();
echo $id->id;// will echo only id one time
阅读https://www.codeigniter.com/user_guide/database/results.html
答案 2 :(得分:1)
$query = $this->db->select('id')->where(array('token_'=>$token))->get('tbl_profile_main');
if($query->num_rows()>0{
//if multiple rows
$result = $query->result_array();
foreach($result as $id){
echo $id['id'];
}
//if one row
// $id = $query->row();
// echo $id->id;
}
答案 3 :(得分:0)
尝试
$query = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."';");
$row = $query->row();
if (isset($row))
{
echo $row->id;
}
对于倍数结果
$query = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."';");
foreach ($query->result() as $row)
{
echo $row->id; // Echo id of all result and retun as object
}
答案 4 :(得分:-1)
如果有一行:
$id = $id->row_array()['id'];
如果有多行:
foreach($id->result_array() as $ids) {
print $ids['id']; // or save to an array or whatever you please
}