Why $context->table(‘book’) dont give me all data fields

Notice: This thread is very old.
alnux
Member | 106
+
0
-

Hi there again i have a litle question why when i use some times

$context->table('book');

request just have the id and not the others data fields and other times this same method calls everything.

i know that i can use

$context->table('book')->select('*');

an example of this you will find on my beginners code post “Paises.php” model file line 66 where instead

return $this->database->table($this->tabla)->where($field, $value);

i wrote

return $this->database->table($this->tabla)->select('*')->where($field, $value);

To take every fields

Hugs

Last edited by alnux (2014-05-26 22:37)

s4muel
Member | 92
+
0
-

you dont need to do select('*'), the where() method returns powerful Database\Table\Selection, if you want to get all its data, just append fetchAll(), e.g.:

return $this->database->table($this->tabla)->where($field, $value)->fetchAll();

or simply acceess the columns you need like this:

$books = $this->database->table($this->tabla)->where($field, $value);
foreach($books as $book) {
	dump($book->column_name_1);
	dump($book->author);
	dump($book->title);
	//...
}