2016-04-15 52 views
-2

呼應的值我如何獲得id的值從下列查詢如何從選擇查詢的笨

$id = $this->db->query("SELECT id from tbl_profile_main WHERE token_='".$token."';"); 
+0

它一次只返回一行還是多行可以返回? –

+0

一次只有一行 –

回答

3

嘗試:

$row = $id->row(); 
echo $row->id; 
+0

感謝兄弟工作 –

+0

您能否接受我的回答? –

-1

如果一個行:

$id = $id->row_array()['id']; 

如果多行:

foreach($id->result_array() as $ids) { 
    print $ids['id']; // or save to an array or whatever you please 
} 
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; 



} 
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   
}