• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not getting the result I'm expecting from this simple query

#1
[eluser]dallen33[/eluser]
Code:
$query = $this->db->get_where('clients', array('name' => $name))->row()->id;
        
        if ($query->num_rows() > 0):
            return $query->result();
        else:
            return false;
        endif;

Any idea what I'm doing wrong? I'm expecting to get the actual ID from "return $query->result();". What might I be doing wrong?

#2
[eluser]pickupman[/eluser]
Once you call the the query ->row() method, $query is not a result object. That means $query->num_rows() will be false. Use this instead.
Code:
$query = $this->db->get_where('clients', array('name' => $name))->row();
        
if ( count($query) > 0)
   return $query->id;
        
return FALSE;
The else is not needed as there is only one other option to return which is FALSE.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.