我正在玩一个zencart试图让它做我想做的事情,但我已经没有想到谷歌的想法了。
当我使用zencart函数查询数据库时,软件会返回一个如下所示的对象:
queryFactoryResult Object
(
[is_cached] =>
[resource] => Resource id #117
[cursor] => 11
[EOF] =>
[fields] => Array
(
[products_id] => 5582
[products_description] => description here
[products_name] => Lucky magnet – Each petal...
[products_type] => 1
[products_quantity] => 0
[products_image] => EachPetalMag.jpg
[products_price] => 3.4000
[products_status] => 1
[products_ordered] => 14
[master_categories_id] => 21
[supplier_id] => 7
)
)
在我做其他事情之前,我必须循环一次以计算有多少个master_categories:
while (!$products->EOF) {
$products_count++;
$supcats[$products->fields['master_categories_id']] = $products->fields['master_categories_id'];
$products->MoveNext();
}
然后我需要使用像上面的while循环再次遍历对象,我试过了:
reset($products);
和
$products->EOF = FALSE;
但它们不起作用。有没有办法在不必再次发送查询的情况下执行此操作?
答案 0 :(得分:0)
Zen Cart上的常规类数组操作queryFactoryResult不起作用,因为它不是数组,所以这不起作用:
reset($products);
要循环遍历变量,请使用queryFactoryResult-> Move(row_number)方法:
$products->Move(0);