呼應的值我如何獲得id的值從下列查詢如何從選擇查詢的笨
$id = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."';");
呼應的值我如何獲得id的值從下列查詢如何從選擇查詢的笨
$id = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."';");
嘗試:
$row = $id->row();
echo $row->id;
感謝兄弟工作 –
您能否接受我的回答? –
要選擇查詢使用->row()
id
$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
你有沒有檢查答案? – Saty
是的,它的工作。 –
如果一個行:
$id = $id->row_array()['id'];
如果多行:
foreach($id->result_array() as $ids) {
print $ids['id']; // or save to an array or whatever you please
}
$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
}
它一次只返回一行還是多行可以返回? –
一次只有一行 –