如何从以下查询中获取id的值
$id = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."';");
尝试:
$row = $id->row();
echo $row->id;
要从选择查询中回显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
$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;
}
尝试
$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
}
如果一行:
$id = $id->row_array()['id'];
如果有多行:
foreach($id->result_array() as $ids) {
print $ids['id']; // or save to an array or whatever you please
}