function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page', $number_of_rows = '')
 {
     global $HTTP_GET_VARS, $HTTP_POST_VARS;
     $this->sql_query = $query;
     $this->page_name = $page_holder;
     if (isset($HTTP_GET_VARS[$page_holder])) {
         $page = $HTTP_GET_VARS[$page_holder];
     } elseif (isset($HTTP_POST_VARS[$page_holder])) {
         $page = $HTTP_POST_VARS[$page_holder];
     } else {
         $page = '';
     }
     if (empty($page) || (int) $page == 0) {
         $page = 1;
     }
     $this->current_page_number = $page;
     if (strlen($number_of_rows) > 0) {
         $this->number_of_rows = $number_of_rows;
     } else {
         $pos_to = mb_strlen($this->sql_query, 'CP1251');
         $pos_from = mb_strpos($this->sql_query, ' from', 0, 'CP1251');
         $pos_group_by = mb_strpos($this->sql_query, ' group by', $pos_from, 'CP1251');
         if ($pos_group_by < $pos_to && $pos_group_by != false) {
             $pos_to = $pos_group_by;
         }
         if ($pos_group_by != false) {
             if (preg_match('/group by ([^\\s|,]+)/i', $this->sql_query, $regs)) {
                 $count_key = trim($regs[1]);
             }
         }
         $pos_having = mb_strpos($this->sql_query, ' having', $pos_from, 'CP1251');
         if ($pos_having < $pos_to && $pos_having != false) {
             $pos_to = $pos_having;
         }
         $pos_order_by = mb_strpos($this->sql_query, ' order by', $pos_from, 'CP1251');
         if ($pos_order_by < $pos_to && $pos_order_by != false) {
             $pos_to = $pos_order_by;
         }
         if (mb_strpos($this->sql_query, 'distinct', 0, 'CP1251') || mb_strpos($this->sql_query, 'group by', 0, 'CP1251')) {
             $count_string = 'distinct ' . tep_db_input($count_key);
         } else {
             $count_string = tep_db_input($count_key);
         }
         $count_query = tep_db_unbuffered_query("select count(" . $count_string . ") as total " . mb_substr($this->sql_query, $pos_from, $pos_to - $pos_from, 'CP1251'));
         $count = tep_db_fetch_array($count_query);
         $this->number_of_rows = $count['total'];
     }
     $this->number_of_rows_per_page = $max_rows > 0 ? $max_rows : $this->number_of_rows;
     $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page);
     if ($this->current_page_number > $this->number_of_pages) {
         $this->current_page_number = $this->number_of_pages;
     }
     $offset = $this->number_of_rows_per_page * ($this->current_page_number - 1);
     $this->sql_query .= " limit " . $offset . ", " . $this->number_of_rows_per_page;
 }
Ejemplo n.º 2
0
 } else {
     $form_link = $form_link . '?action=[form_action]';
 }
 while (strpos($form_link, '?&')) {
     $form_link = str_replace('?&', '?', $form_link);
 }
 while (strpos($form_link, '&&')) {
     $form_link = str_replace('&&', '&', $form_link);
 }
 $cur_row = 0;
 //	if ($customer_id==2) echo $listing_sql;
 $listing = array();
 if ($show_listing_string == false) {
     $listing_query = tep_db_unbuffered_query($listing_sql);
 } else {
     $listing_query = tep_db_unbuffered_query($listing_split->sql_query);
 }
 while ($row = tep_db_fetch_row($listing_query)) {
     $listing[] = $row[0];
 }
 reset($listing);
 while (list($rows, $product_id) = each($listing)) {
     $product_info_query = tep_db_query("select " . $select_column_list . " p.* from " . TABLE_PRODUCTS . " p where p.products_id = '" . (int) $product_id . "'");
     $product_info = tep_db_fetch_array($product_info_query);
     $product_info['final_price'] = $product_info['products_price'];
     $product_info['specials_new_products_price'] = 0;
     $product_info['specials_name'] = '';
     $product_info['specials_description'] = '';
     $special_info_query = tep_db_query("select specials_name, specials_description, specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int) $product_id . "' and status > '0' and specials_new_products_price > '0' and specials_new_products_price < '" . $product_info['products_price'] . "' and language_id = '" . (int) $languages_id . "' order by specials_date_added desc limit 1");
     if (tep_db_num_rows($special_info_query) > 0) {
         $special_info = tep_db_fetch_array($special_info_query);