CodeIgniter - return only one row?

后端 未结 10 1365
鱼传尺愫
鱼传尺愫 2020-12-01 02:43

At the moment if I am doing a query on the database that should only return one row, using:

...query stuff...
$query = $this->db->get();
$ret = $query-         


        
10条回答
  •  半阙折子戏
    2020-12-01 03:15

    To add on to what Alisson said you could check to see if a row is returned.

    // Query stuff ...
    $query = $this->db->get();
    
    if ($query->num_rows() > 0)
    {
        $row = $query->row(); 
        return $row->campaign_id;
    }
    
    return null; // or whatever value you want to return for no rows found
    

提交回复
热议问题