1

Hi i need to do a simple query but something is wrong. I have $name and $surname and i need to search the (possible multiple) id that rappresent that name and surname and put all the id, name and surname in a array I do this query:

$result=$this->_db_table->select()->where('name=?',$name)
    ->where('surname=?', $surname)->query()
    ->fetchAll();

$array=$result->toArray();
return $array;

If i use

$result=$this->_db_table->fetchAll();
$array=$result->toArray();
return $array

it work correctly and i have an array whith all the value in the database in that table. What is wrong in my first code???

tawfekov
  • 5,084
  • 3
  • 28
  • 51
Simone
  • 85
  • 1
  • 9

1 Answers1

1

After doing this

$result=$this->_db_table->select()->where('name=?',$name)
    ->where('surname=?', $surname)->query()
    ->fetchAll();

$result is already an array its not an object . So simply use it instead of calling toArray on it.

Correct code wd be

$result=$this->_db_table->select()->where('name=?',$name)
    ->where('surname=?', $surname)->query()
    ->fetchAll();

return $result;
Mr Coder
  • 8,169
  • 5
  • 45
  • 74