obtain values from context query result

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

Hi everyone,

I have maybe very simple thing for you. Ok i will take the script from the database documentation

<script>
$selection = $context->table('book'); // db table name is "book"
$books = $context->table('book');
foreach ($books as $book) {
    echo $book->title;
    echo $book->author_id;
}
</script>

my query have just one result and it does not necesary make a foreach, could somebody help me with this maybe easy thing.

how can i get the query values without foreach,

PD. dont say me get() method becouse i dont have any id

really thanks

s4muel
Member | 92
+
0
-
$item = $context->table('table_name')->fetch();
echo($item->table_column_1);
echo($item->table_column_2);

check the fetchAll() and fetchPairs() methods as well

English documentation – nette 2.1 database selection

alnux
Member | 139
+
0
-

s4muel wrote:

$item = $context->table('table_name')->fetch();
echo($item->table_column_1);
echo($item->table_column_2);

check the fetchAll() and fetchPairs() methods as well

English documentation – nette 2.1 database selection

Thanks samuel if my english is bad my Czech is worse.. thanks yandex translation