Welcome Guest, Not a member yet? Register   Sign In
Displaying data from query from single row
#1

[eluser]Gukkie[/eluser]
Hi, just got a few doubts to clear.

Lets say i have a query in the Model such as,

Code:
function getData()
{
  $sql = "SELECT id, username FROM users WHERE email = ?";
  $binds = "[email protected]";
  $query = $this->db->query($sql, $binds);
  $data = array();

  if($query->num_rows() > 0)
  {
    foreach($query->result_array() as $row)
   {
     $data[] = array(
          'id' => $row->id,
          'username' => $row->username    
     );
   }
  return $data;
  }
  else
  {
    return FALSE;
  }
}

do i still have to use a "foreach" loop as im not getting data from multiple rows?

Also, is there a simpler way of displaying data from a Model to a Controller?

Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB