0

我在 NotORM 代码中遇到问题。

这段代码运行良好:

$select = $db->pspaym->select("COUNT(*)")->where("F4","$textdate")->fetch(); $count = count($select);

但是这里的代码不起作用:

$select = $db->pssale->select("COUNT(*)")->where("F8","$textdate")->fetch(); $count = count($select); 此代码有一条错误消息说:

“试图获得非对象的属性”

无法解决此问题。

所有变量都不为空。

谢谢。

4

1 回答 1

0

if you want to count lines in a table, simply use:

$select = $db->pspaym->where("F4","$textdate");
$count = count($select);

The problem comes from your combination of fetch() and count() methods. Because of the ending fetch call, $select doesn't contain a Table object, but a Record object.

So count($select) will count the number of columns in your record. Normally, it should always returns 1 (because one field in the returned record).

For your information, if you want to be uselessly explicit, you may do something like this.

$record = $db->pspaym("F4","$textdate")->select("COUNT(*) AS c")->fetch();
$count = $record['c'];

But, that's the long way.

于 2014-08-21T13:20:45.020 回答