Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getFiltered($post_arr, $page = 1, $order = 'ASC') {
- global $lang;
- //printr($_POST); die();
- $manuf = isset($post_arr['manuf']) ? $post_arr['manuf'] : 0;
- $razotajs = isset($post_arr['razotajs']) ? explode(',', $post_arr['razotajs']) : array();
- $category_id = $post_arr['category_id'];
- $select = array_filter($post_arr['select']);
- $where = $goods = $selects = $types = array();
- if (is_numeric($page))
- $bot = ($page - 1) * 9;
- else
- $bot = 0;
- // print "Post data:"; printr($post_arr);
- // print "Select:"; printr($select);
- $query = "SELECT * FROM `filters_options` WHERE `filters_id` IN (" . implode(',', array_keys($select)) . ") AND `option`!='';";
- $tmp_q = mysql_query($query);
- while ($tmp = mysql_fetch_object($tmp_q)) {
- $types[$tmp->id] = $tmp->type;
- $selects[$tmp->filters_id][$tmp->id] = $tmp->option;
- }
- foreach ($select as $filter => $option) {
- if ($filter == $manuf) {
- $where[] = "g.`razotajs` = '" . $razotajs[$option - 1] . "'";
- continue;
- }
- if (is_array($option)) {
- $cond = '(';
- foreach ($option as $opt) {
- $cond .= "g.`params` LIKE '%-$option-%' OR ";
- }
- $cond = rtrim($cond, ' OR ') . ')';
- } else {
- if ($option == "cits") {
- $cond = " g.`params` not in (select g.`params` from `goods` g where g.`params` like '%-$filter,%' or g.`params` like '%$filter') ";
- } elseif ($types[$option] == 'opt') {
- $cond = "g.`params` LIKE '%-$option-%'";
- } elseif ($types[$option] == 'to') {
- $cond = '(';
- foreach ($selects[$filter] as $_option => $check) {
- if ($check <= $selects[$filter][$option])
- $cond .= "g.`params` LIKE '%-$_option-%' OR ";
- }
- $cond = rtrim($cond, ' OR ') . ')';
- }elseif ($types[$option] == 'from') {
- $cond = '(';
- foreach ($selects[$filter] as $_option => $check) {
- if ($check >= $selects[$filter][$option])
- $cond .= "g.`params` LIKE '%-$_option-%' OR ";
- }
- $cond = rtrim($cond, ' OR ') . ')';
- }
- }
- $where[] = $cond;
- }
- //printr($where); die();
- $q = "SELECT SQL_CALC_FOUND_ROWS g.*, cat.`cartridge`, $this->akc_fields FROM `goods` g
- JOIN `category_comp` as c on c.`suplier`=g.`suplier` AND c.`suplier_category`=g.`suplier_category` AND c.`sub`=g.`sub`
- AND c.`category_id` = '$category_id'
- LEFT JOIN `category_data` as cat on cat.`id`=c.`category_id`
- LEFT JOIN `akcijas` as akc on akc.`preces_id`=g.`id` AND akc.`suplier`=g.`suplier`
- LEFT JOIN `alike` as a on a.`goods_id`=g.`id`
- WHERE " . ((!empty($where)) ? implode(' AND ', $where) . ' AND' : '') . " (a.`order`=0 OR a.`order` IS NULL)
- ORDER BY `mazumcena` $order LIMIT $bot,9;
- "; // GROUP BY g.`id`
- //echo $q; die();
- $tmp_q = mysql_query($q) or die(mysql_error());
- $total = mysql_result(mysql_query("SELECT FOUND_ROWS()"), 0);
- while ($g = mysql_fetch_object($tmp_q)) {
- $goods[$g->id] = $this->processGood($g);
- }
- $goods = $this->goodlang($goods);
- return array('goods' => $goods, 'total' => $total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement