Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. public function getFiltered($post_arr, $page = 1, $order = 'ASC') {
  2. global $lang;
  3.  
  4. //printr($_POST); die();
  5.  
  6. $manuf = isset($post_arr['manuf']) ? $post_arr['manuf'] : 0;
  7. $razotajs = isset($post_arr['razotajs']) ? explode(',', $post_arr['razotajs']) : array();
  8. $category_id = $post_arr['category_id'];
  9. $select = array_filter($post_arr['select']);
  10. $where = $goods = $selects = $types = array();
  11.  
  12. if (is_numeric($page))
  13. $bot = ($page - 1) * 9;
  14. else
  15. $bot = 0;
  16.  
  17. // print "Post data:"; printr($post_arr);
  18. // print "Select:"; printr($select);
  19.  
  20. $query = "SELECT * FROM `filters_options` WHERE `filters_id` IN (" . implode(',', array_keys($select)) . ") AND `option`!='';";
  21. $tmp_q = mysql_query($query);
  22. while ($tmp = mysql_fetch_object($tmp_q)) {
  23. $types[$tmp->id] = $tmp->type;
  24. $selects[$tmp->filters_id][$tmp->id] = $tmp->option;
  25. }
  26.  
  27. foreach ($select as $filter => $option) {
  28. if ($filter == $manuf) {
  29. $where[] = "g.`razotajs` = '" . $razotajs[$option - 1] . "'";
  30. continue;
  31. }
  32. if (is_array($option)) {
  33. $cond = '(';
  34. foreach ($option as $opt) {
  35. $cond .= "g.`params` LIKE '%-$option-%' OR ";
  36. }
  37. $cond = rtrim($cond, ' OR ') . ')';
  38. } else {
  39. if ($option == "cits") {
  40. $cond = " g.`params` not in (select g.`params` from `goods` g where g.`params` like '%-$filter,%' or g.`params` like '%$filter') ";
  41. } elseif ($types[$option] == 'opt') {
  42. $cond = "g.`params` LIKE '%-$option-%'";
  43. } elseif ($types[$option] == 'to') {
  44. $cond = '(';
  45. foreach ($selects[$filter] as $_option => $check) {
  46. if ($check <= $selects[$filter][$option])
  47. $cond .= "g.`params` LIKE '%-$_option-%' OR ";
  48. }
  49. $cond = rtrim($cond, ' OR ') . ')';
  50. }elseif ($types[$option] == 'from') {
  51. $cond = '(';
  52. foreach ($selects[$filter] as $_option => $check) {
  53. if ($check >= $selects[$filter][$option])
  54. $cond .= "g.`params` LIKE '%-$_option-%' OR ";
  55. }
  56. $cond = rtrim($cond, ' OR ') . ')';
  57. }
  58. }
  59. $where[] = $cond;
  60. }
  61. //printr($where); die();
  62.  
  63. $q = "SELECT SQL_CALC_FOUND_ROWS g.*, cat.`cartridge`, $this->akc_fields FROM `goods` g
  64. JOIN `category_comp` as c on c.`suplier`=g.`suplier` AND c.`suplier_category`=g.`suplier_category` AND c.`sub`=g.`sub`
  65. AND c.`category_id` = '$category_id'
  66. LEFT JOIN `category_data` as cat on cat.`id`=c.`category_id`
  67. LEFT JOIN `akcijas` as akc on akc.`preces_id`=g.`id` AND akc.`suplier`=g.`suplier`
  68. LEFT JOIN `alike` as a on a.`goods_id`=g.`id`
  69. WHERE " . ((!empty($where)) ? implode(' AND ', $where) . ' AND' : '') . " (a.`order`=0 OR a.`order` IS NULL)
  70. ORDER BY `mazumcena` $order LIMIT $bot,9;
  71. "; // GROUP BY g.`id`
  72. //echo $q; die();
  73.  
  74. $tmp_q = mysql_query($q) or die(mysql_error());
  75. $total = mysql_result(mysql_query("SELECT FOUND_ROWS()"), 0);
  76. while ($g = mysql_fetch_object($tmp_q)) {
  77. $goods[$g->id] = $this->processGood($g);
  78. }
  79.  
  80. $goods = $this->goodlang($goods);
  81.  
  82. return array('goods' => $goods, 'total' => $total);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement