How to count rows in Nette Database?

4 years ago

alfanumeric
Member | 3
+
0
-

Hello, how can I get number of results from query?

$q = $this->database->query('SELECT * FROM post WHERE ID = ?', $id);

I don't understand your API but I found only this:

$q->count

Cannot read an undeclared property Nette\Database\ResultSet::$count.

And

count($q)

= 1 all times.

Last edited by alfanumeric (2015-07-05 21:17)

4 years ago

besanek
Member | 128
+
+1
-

Try this:

$q->getRowCount();

4 years ago

alfanumeric
Member | 3
+
0
-

Thank you very much. Why this is not specified in the API?

4 years ago

mrtnzlml
Member | 145
+
0
-

Yes, it is: https://api.nette.org/…sultSet.html#…. This API should be more important for you.

4 years ago

Šaman
Member | 2349
+
0
-

There are Nette\Database\Table\Selection and Nette\Database\ResultSet
Most of examples show rich Nette\Database\Table, but you use simple query and that function returns ResultSet.