$q .= ' OR '; } $q .= ' product_application = "' . $applicationFilters[$i] . '" '; } $query = $query->where($q); } if (isset($_GET['color'])) { $p = ''; for ($i = 0; $i < sizeof($colorFilters); $i++) { if ($i > 0) { $p .= ' OR '; } $c_id = $db->colors->where('color_name = "' . $colorFilters[$i] . '" '); $p .= ' colors_id = ' . $c_id->fetch() . ' '; } $q = $db->product_colors()->where($p)->select('products_id'); $query = $query->where('id', $q); } $totalResults = count($query); $start = ($pageNo - 1) * (int) $resultPerPage; $last = $start + $resultPerPage; if ($last > $totalResults) { $last = $totalResults; } $query = $query->order('product_price ASC'); $query = $query->limit(30, $start); //echo $query; $data = findAllProducts($query, ''); $app->response()->header('content-type', 'application/json'); echo json_encode(array('totalResults' => $totalResults, 'start' => $start, 'last' => $last, 'product_data' => $data)); });