please, could you help me with this problem?:
I'm getting products sorted ASC or DESC by title or price. If I sort them ASC, there is no problem - I loop products in foreach and adding generated string into variable. But if products are sorted DESC, there is problem - I'm looping them via foreach but html is not adding into variable (I tried to print_r variable $products, so I know, it wasn't empty..) - I hope that if you look at code bellow, my question would be clear. Do you know, where might be problem? Thank you very much.
I also tried to call this code not via ajax, but go to the url of ajax script and behavior is same...
EDIT:
I tried to echo $products_html
before adding $products_html
into $return['products_html']
and in $products_html
is correctly generated html... I'm quite confused what does this mean...
EDIT 2: when I print_r $return, it is all ok - products html is stored in $return['products_html']. Problem is, when I json_encode it. But I really don't know, where is the problem...
Here is code:
$products_html = '';
$products = $this->products_model->get_products_specified($filter); // here i load products into variable
foreach($products as $product){ // here i loop them
$products_html .= view_loader('products/product_small', array('product' => $product), true); // view load returns html for product
}
$return['products_html'] = $products_html;
$return['params_url'] = base_url().'individual/'.generate_url_from_parameters($filter);
$return['status'] = 1;
$return['filter'] = $filter;
echo json_encode($return); // echo for ajax return