Jump to content
Sign in to follow this  
nrlatsha

[Contribution] Fancy split_page_results

Recommended Posts

This is the support thread for Fancy split_page_results contribution.

 

This modification replaces the default style of multi-page links included with osCommerce with an easier to use navigation style. Using this modification the result pages are no longer 'windowed' into groups of length $max_page_links and individually linked. Instead all pages are accessible from a drop-down list. The selected page is automatically loaded using this drop-down's "onChange" property. The previous and next "[<< Previous]" are replaced with buttons, which are on the far right; the count is incorporated.

 

Easy to install too.

 

You can get it here: http://www.oscommerce.com/community/contributions,630

 

You can see an example here: www.nabcomdiamonds.com

 

Noel

Edited by nrlatsha

9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

Noel,

 

It is me again. I tried to install this but get the following parse error.

 

Parse error: parse error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/talk2mag/public_html/newstore2/includes/classes/split_page_results.php on line 192

 

Any idea?

Share this post


Link to post
Share on other sites

Hello Peter, Are you following me?!? :P

Can you post line 92, with a couple above and below?


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

Noel,

 

Here are lines 85-93

 

// check if number_of_pages > $max_page_links
     $cur_window_num = intval($this->current_page_number / $max_page_links);
     if ($this->current_page_number % $max_page_links) $cur_window_num++;

     $max_window_num = intval($this->number_of_pages / $max_page_links);
     if ($this->number_of_pages % $max_page_links) $max_window_num++;

// previous window of pages
     if ($cur_window_num > 1) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>';

Share this post


Link to post
Share on other sites

according to the error message that should be around 192

 

sorry for interrupting your conversation ;)


Robert

 

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

Share this post


Link to post
Share on other sites

Well, here is 182-193

 

   	 echo '<td class="smallText" valign="right" >';

    if (($current_page_number < $num_pages) && ($num_pages != 1)) echo ' <a href="' . tep_href_link(basename($PHP_SELF), $parameters . 'page=' . ($current_page_number + 1) . '&numrows=' . $rows, 'NONSSL') . '">' . tep_image_button('button_next.gif', IMAGE_BUTTON_NEXT) . '</a>';
 
    echo '</td>';
 echo '</table>';

}
}
 
?>

 

Thanks again for your help.

Share this post


Link to post
Share on other sites

Peter - Can you post the entire file here, I don't see anything wrong with 192 or the surrounding code.


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

Here is the entire file.

 

<?php

/*

  $Id: split_page_results.php,v 1.15 2003/06/09 22:35:34 hpdl Exp $

 

  osCommerce, Open Source E-Commerce Solutions

  http://www.oscommerce.com

 

  Copyright ? 2003 osCommerce

 

  Released under the GNU General Public License

*/

 

  class splitPageResults {

    var $sql_query, $number_of_rows, $current_page_number, $number_of_pages, $number_of_rows_per_page, $page_name;

 

/* class constructor */

    function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page') {

      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) || !is_numeric($page)) $page = 1;

      $this->current_page_number = $page;

 

      $this->number_of_rows_per_page = $max_rows;

 

      $pos_to = strlen($this->sql_query);

      $pos_from = strpos($this->sql_query, ' from', 0);

 

      $pos_group_by = strpos($this->sql_query, ' group by', $pos_from);

      if (($pos_group_by < $pos_to) && ($pos_group_by != false)) $pos_to = $pos_group_by;

 

      $pos_having = strpos($this->sql_query, ' having', $pos_from);

      if (($pos_having < $pos_to) && ($pos_having != false)) $pos_to = $pos_having;

 

      $pos_order_by = strpos($this->sql_query, ' order by', $pos_from);

      if (($pos_order_by < $pos_to) && ($pos_order_by != false)) $pos_to = $pos_order_by;

 

      if (strpos($this->sql_query, 'distinct') || strpos($this->sql_query, 'group by')) {

        $count_string = 'distinct ' . tep_db_input($count_key);

      } else {

        $count_string = tep_db_input($count_key);

      }

 

      $count_query = tep_db_query("select count(" . $count_string . ") as total " . substr($this->sql_query, $pos_from, ($pos_to - $pos_from)));

      $count = tep_db_fetch_array($count_query);

 

      $this->number_of_rows = $count['total'];

 

      $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;

    }

 

/* class functions */

 

// display split-page-number-links

    function display_links($max_page_links, $parameters = '') {

      global $PHP_SELF, $request_type;

 

      $display_links_string = '';

 

      $class = 'class="pageResults"';

 

      if (tep_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&';

 

// previous button - not displayed on first page

      if ($this->current_page_number > 1) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . ($this->current_page_number - 1), $request_type) . '" class="pageResults" title=" ' . PREVNEXT_TITLE_PREVIOUS_PAGE . ' "><u>' . PREVNEXT_BUTTON_PREV . '</u></a>  ';

 

// check if number_of_pages > $max_page_links

      $cur_window_num = intval($this->current_page_number / $max_page_links);

      if ($this->current_page_number % $max_page_links) $cur_window_num++;

 

      $max_window_num = intval($this->number_of_pages / $max_page_links);

      if ($this->number_of_pages % $max_page_links) $max_window_num++;

 

// previous window of pages

      if ($cur_window_num > 1) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>';

 

// page nn button

      for ($jump_to_page = 1 + (($cur_window_num - 1) * $max_page_links); ($jump_to_page <= ($cur_window_num * $max_page_links)) && ($jump_to_page <= $this->number_of_pages); $jump_to_page++) {

        if ($jump_to_page == $this->current_page_number) {

          $display_links_string .= ' <b>' . $jump_to_page . '</b> ';

        } else {

          $display_links_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . $jump_to_page, $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' "><u>' . $jump_to_page . '</u></a> ';

        }

      }

 

// next window of pages

      if ($cur_window_num < $max_window_num) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . (($cur_window_num) * $max_page_links + 1), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a> ';

 

// next button

      if (($this->current_page_number < $this->number_of_pages) && ($this->number_of_pages != 1)) $display_links_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), $parameters . 'page=' . ($this->current_page_number + 1), $request_type) . '" class="pageResults" title=" ' . PREVNEXT_TITLE_NEXT_PAGE . ' "><u>' . PREVNEXT_BUTTON_NEXT . '</u></a> ';

 

      return $display_links_string;

    }

 

// display number of total products found

    function display_count($text_output) {

      $to_num = ($this->number_of_rows_per_page * $this->current_page_number);

      if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows;

 

      $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1));

 

      if ($to_num == 0) {

        $from_num = 0;

      } else {

        $from_num++;

      }

 

      return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);

    // display fancy split-page-number-links

function display_fancy_links($max_page_links, $parameters = '', $rows, $current_page_number, $count_text)

{

global $PHP_SELF;

  echo '<table>';

 

// calculate number of pages needing links

    $num_pages = intval($rows / MAX_DISPLAY_SEARCH_RESULTS);

 

// $num_pages now contains int of pages needed unless there is a remainder from division

    if ($rows % MAX_DISPLAY_SEARCH_RESULTS) $num_pages++; // has remainder so add one page

 

  if ($current_page_number == '') $current_page_number = 1;

    if($num_pages != 1)

  {

 

  // $current_page_number = TEXT_RESULT_PAGE;

      echo '<td class="smallText" valign="right" >';

 

  if ($current_page_number > 1) {

  echo '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . '&page=' . ($current_page_number - 1) . '&numrows=' . $rows, 'NONSSL') . '">' . tep_image_button('button_previous.gif', IMAGE_BUTTON_PREVIOUS);

  }

 

            echo '</a></td>';

  echo '<td class="smallText" valign="right" >'; ?>

 

      <form name="jump_to" method="get" action="<?php echo tep_href_link(basename($PHP_SELF)); ?>">

 

  <?php

  $pairs = explode("&", $parameters);

  foreach($pairs as $pair)

  {

    list($key,$value) = explode("=", $pair);

    echo tep_draw_hidden_field(rawurldecode($key), rawurldecode($value));

  }

 

  ?>

 

  <select name="page" onChange="submit();">

  <?php

        for ($jump_to_page = 1 ; ($jump_to_page <= $num_pages); $jump_to_page++) {

        if ($jump_to_page == $current_page_number) {

     

          echo '<option value='. $jump_to_page .' SELECTED>' . $jump_to_page . '</option>';

          }

        else

        {

 

          echo '<option value='. $jump_to_page . '>' . $jump_to_page . '</option>';

        }

  }

      ?>

      </select></form>

    <?php

    }

 

    echo '<td class="smallText" valign="right" >';

 

    if (($current_page_number < $num_pages) && ($num_pages != 1)) echo ' <a href="' . tep_href_link(basename($PHP_SELF), $parameters . 'page=' . ($current_page_number + 1) . '&numrows=' . $rows, 'NONSSL') . '">' . tep_image_button('button_next.gif', IMAGE_BUTTON_NEXT) . '</a>';

 

    echo '</td>';

  echo '</table>';

 

}

}

 

?>

Edited by magicproshop

Share this post


Link to post
Share on other sites

Peter -

 

Chage this:

     return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
   // display fancy split-page-number-links

 

To This:

return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
   }
   // display fancy split-page-number-links

 

Took too many }'s in the replace with part of the instructions, my bad.

 

Lemme know if it works.

 

I'll update the instructions and re-load soon.

 

Noel


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

A great Contribution. Works like a charm and is as easy to install as you expect a good contribution to be.

 

I installed it both on a standard and a loaded6 installation and it works flawlessly.

 

Thanks very much as I was waiting for something like this for a long long time. :D

Share this post


Link to post
Share on other sites

Glad you like it Scotty :D


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

There is a very good button maker for anybody that wants to create their own buttons:

 

http://www.grsites.com/button/


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

how come products_new.php doesn't work with this great contribution... hmm

 

I just noticed that my what's new product page still uses the original OSC text prev and next link... HOW can I change it?

 

I've installed all products and it works fine...

 

What's going on here..

 

BTW, thanks for the great contribution.. it's beautiful!!

Share this post


Link to post
Share on other sites

I installed this mod and, oddly enough, it didn't change anything. I still have to text links for pages at the top of every page that requires them. I'm using AABox MAX version of OSC with BTS.

 

Any ideas?

WishX

Share this post


Link to post
Share on other sites
how come products_new.php doesn't work with this great contribution... hmm

 

I just noticed that my what's new product page still uses the original OSC text prev and next link... HOW can I change it?

 

I've installed all products and it works fine...

 

What's going on here..

 

BTW, thanks for the great contribution.. it's beautiful!!

I must have missed that one, and probably some more...

 

Go into catalog/products_new.php

 

LOOK FOR:

$products_new_split = new splitPageResults($products_new_query_raw, MAX_DISPLAY_PRODUCTS_NEW);

 

ADD under that line:

$rows = ($products_new_split->number_of_rows);
$current_page = $HTTP_GET_VARS['page'];

 

LOOK FOR:

$products_new_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y')));

 

It'll be there twice and

 

CHANGE TO:

$products_new_split->display_fancy_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y')), $rows, $current_page, TEXT_DISPLAY_NUMBER_OF_PRODUCTS);

 

That should be it...


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

it seems working..but doesn't show me all pages..

 

Before I changed it, I had 4 pages for the new product.

 

Now, Dropdown menu shows me only 2 pages..

 

page number 3 and 4 are still there (I checked maually by typing 3 and 4

on URL address at the top. )

 

WHat is wrong?

Share this post


Link to post
Share on other sites

I guess I found the reason why it doesn't work well..

 

I installed "View All Products" and it displays 20 items on each page.

 

As the number of page increases in all product page, the number of page in the product new page goes up. (The page number just follows up the all product page.)

 

The problem is this.

 

The number of item shown in the product new page is 10 and 20 for all products(I don't know how to edit this number though..)

 

Since their scales are different, I don't know how to handle this..

 

I guess the easiest way to solve this error is to change 20 to 10 or

 

make 2 columns in the product new pages so that each column can have 10 items each(which makes the total 20.) I think it's better...

 

Well.. I don't know whether I can ask such an unrelated question....

 

But, it should be looking a lot better...

 

How do you think?

 

If you don't mind, can you take a look at product_new.php code so that

all new products are displayed in 2 columns (I think the default setting for this is

10 products in one column per a page)

Share this post


Link to post
Share on other sites
If you don't mind, can you take a look at product_new.php code so that

all new products are displayed in 2 columns (I think the default setting for this is

10 products in one column per a page)

The products_new.php code for default file, or the view all one you have installed? If its the default, I can take a look this weekend. If its custom or a contrib, can you post it here?


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

View All Product is one of the contributions I've installed.. and its address is this.

http://www.oscommerce.com/community/contributions,1785

 

 

As I've already explained above, because of all_product.php I can't list all my products in catalog/products_new.php

 

Basically the number of catalog/products_new.php and catalog/all_products.php are the same and from the admin page ->config -> MAX values

 

Search Results works with all_products.php and New Products Listing works with products_new.php.

 

Right now I've set them up to 16 so that they have the equal split number.

 

If I set 16 for search results and 12 for New Products Listing, then the split page number will be up to 2 for all products and 2 for New Products Listing as well..

But for New Products Listing, it should be up to 3 because the total item number is 31. (make sense to you?)

 

 

But, if you can split products_new.php into two columns(default is one), then it may take care of this...

 

 

Right now I have one default column and 16 rows for New Products Listing which makes my products_new.php a lot longer from the top..(doesn't look good!!)

 

Another thing that I've noticed from this is...

 

If you use Fancy split page results one time(either in all product or product_new), then it works fine.

 

 

 

When you take a look at the code, if possible, can you think of splitting default products_new.php column(1 column) into two columns?

 

Since I have more than 400 items, it's kinda annoying to show 10 or 16 products in one page... Furthermore, this products_new.php doesn't contain many info... only price, manufactuerer, added date, and buy now button.. that's it..

It wastes lots of spaces where I might put more products...

 

and I didn't modify catalog/products_new.php.. it's the way it is... OSC v.2.2

except the code for split_page_results.. I only modified that part..

 

 

 

BTW thanks for all your support and kindness!!

Share this post


Link to post
Share on other sites

jjanguda - I just want to make sure I'm clear on what you're asking here.

 

You want products_new modified to have two columns instead of one? I don't have time right now, but I may tonight.

 

I did notice what you're talking about though with the incorrect page numbers. I'll have to take a look at that tonight and maybe I'll be able to solve that one as well. I'm just too tired to look at it right now, I'd end up making things worse.

 

Will see tonight


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

I just re-wrote a new function for the products_new and specials page. I'm going to undergo some more testing and then I'll upload the new instructions. There shouldn't be a need for re-writing the products_new page for this contrib.

 

Noel


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

Ran into a slight problem with URL encoding, will have to look at it tonight, for now, I must go to bed.


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

New Version just released:

******************************

 

Fancy Split-Page Results v4.1

 

******************************

 

Get it here: http://www.oscommerce.com/community/contributions,630

 

See it here: www.nabcomdiamonds.com

 

Re-wrote the function for more logical flow.

 

Change notes: 11 July 2004 04:35:59

(1) Re-wrote the entire function, making it cross-compat with specials/new prods/and normal listings

(2) Made nicer instructions.

 

I also made the buttons go into their own table divisions, so the buttons stay in the same place on every page.

 

This upgrade should take care of this issues with specials and new products pages.

 

x-click-but04.gif

 

Post your comments/issues/rants/questions here...

 

Noel


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

Ok, I've made the changes 3 different times, and still the only change I can see on my pages is that I now have the drop down and the next and previous buttons. Is this all I am supposed to see?

 

Also, in IE, I see a border around the results, which is fine...but in Netscape/MozThunderbird I don't see the border..which is how I set it up in css.

 

 

Am I overlooking something?

Share this post


Link to post
Share on other sites
Ok, I've made the changes 3 different times, and still the only change I can see on my pages is that I now have the drop down and the next and previous buttons.  Is this all I am supposed to see?

 

Also, in IE, I see a border around the results, which is fine...but in Netscape/MozThunderbird I don't see the border..which is how I set it up in css.

 

 

Am I overlooking something?

ecopeia - Yes, the only change you will see is in the navigation buttons. To display the results differently, or in columns, install this contrib: http://www.oscommerce.com/community/contributions,825

 

That will give the display the same look as mine. Of course you'll have to make changes to that file for my contrib's portions to work.

 

Noel


9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×