I have a collection of elements :
$products_asc =Model::factory('product')->sale($sale_id)->category($category_id)->order_by('product_id', 'asc')->find_all();
and I want to make a next-previous navigator into this elements. (of course, for getting the previous ones I will开发者_JAVA技巧 have a $products_desc
ordering)
My problem is: I want to make a function having the signature:
public function get_next_product($category, $sale, $id_product)
that will always give me the next product id. but I don't know how to do it. How exactly can i get the next element of the collection having only all the elements sorted ascending by the :
$products_asc =Model::factory('product')->sale($sale_id)->category($category_id)->order_by('product_id', 'asc')->find_all();
i have found the solution - for those who may also be in need:
$previous = Model::factory('product')->sale($sale_id)->order_by('product_id','desc')->where('product_id', '<', $id)->find();
$next = Model::factory('product')->sale($sale_id)->where('product_id', '>', $id)->find();
Database_Result
is a kind of Iterator
object. Why dont use next($products_asc)
and prev($products_asc)
functions?
精彩评论