Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

New Products Limit


Mark123

Recommended Posts

Hello all,

 

I'm having a little trouble trying to limit the number of products being shown in my new products page. At the moment it's showing all the products in my database as you can see here: http://corbett.net.au/irrigation/products_new.php

 

I'm trying to limit the number of products shown to just 10 all up, at the monent it shows 390 new products.

If there is any code I can add or maybe a setting I missed in the admin section, any help would be much appreciated.

 

Thanks in advance,

 

Mark

Link to comment
Share on other sites

Hello all,

 

I'm having a little trouble trying to limit the number of products being shown in my new products page. At the moment it's showing all the products in my database as you can see here: http://corbett.net.au/irrigation/products_new.php

 

I'm trying to limit the number of products shown to just 10 all up, at the monent it shows 390 new products.

If there is any code I can add or maybe a setting I missed in the admin section, any help would be much appreciated.

 

Thanks in advance,

 

Mark

if I am correct the # you want to change is in your admin and it will be under configuration-->maximum values-->new products module, change that number to 10 and you should be set...anyway, I think this is what you want. Hope I have helped!

"I must admit that I personally measure success in terms of the contributions an individual makes to her or his fellow human beings."

---Margaret Mead---

 

"The answer is never the answer. What's really interesting is the mystery. If you seek the mystery instead of the answer, you'll always be seeking. I've never seen anybody really find the answer -- they think they have, so they stop thinking. But the job is to seek mystery, evoke mystery, plant a garden in which strange plants grow and mysteries bloom. The need for mystery is greater than the need for an answer.

--Ken Kesey"

Link to comment
Share on other sites

if I am correct the # you want to change is in your admin and it will be under configuration-->maximum values-->new products module, change that number to 10 and you should be set...anyway, I think this is what you want. Hope I have helped!

 

Thanks for your response rabbitseffort.

I gave that a go, but it still displays all the products from the database.

It does displays 10 products per page of 390 products, but what I'm trying to do is have it display just the latest 10 products. So it would read displaying 10 of 10 products. I gather it's showing all 390 products, because they have all just been added, so they're all new. But I just want it to show the 10 latest products added.

Sorry if I'm not explaining it properly. :blush:

Link to comment
Share on other sites

Thanks for your response rabbitseffort.

I gave that a go, but it still displays all the products from the database.

It does displays 10 products per page of 390 products, but what I'm trying to do is have it display just the latest 10 products. So it would read displaying 10 of 10 products. I gather it's showing all 390 products, because they have all just been added, so they're all new. But I just want it to show the 10 latest products added.

Sorry if I'm not explaining it properly. :blush:

hmmm, wired, I am not sure then, your site looks pretty heavily modified, so maybe there will be more to it. I wanted the same thing for mine, but I only wanted 3 products to show due to my layout, and so that is all that shows for me, I am sure someone else will respond that can help you better. Sorry I couldn't help,

Be well!

"I must admit that I personally measure success in terms of the contributions an individual makes to her or his fellow human beings."

---Margaret Mead---

 

"The answer is never the answer. What's really interesting is the mystery. If you seek the mystery instead of the answer, you'll always be seeking. I've never seen anybody really find the answer -- they think they have, so they stop thinking. But the job is to seek mystery, evoke mystery, plant a garden in which strange plants grow and mysteries bloom. The need for mystery is greater than the need for an answer.

--Ken Kesey"

Link to comment
Share on other sites

If you do not need the quantity of new products to be changed in the future, ie via the admin, you could add the Limit to your SQL statement.

 

In Products_New.php

Line 59 (about)

 

$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";

 

Change to

 

$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name Limit 0,10";

 

Change the 10 in the "Limit 0,10" to the number of products you want to display.

 

This has not been tested by me.

 

Best Wishes

Its Only Me

Alex

Link to comment
Share on other sites

Hi Alex,

 

Thanks for that, I think we're getting close.

When I edited that code with your new code and tried out the new products page, it gave me this error on the page:

 

1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 0, 10' at line 1

 

select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from products p left join manufacturers m on (p.manufacturers_id = m.manufacturers_id), products_description pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' order by p.products_date_added DESC, pd.products_name Limit 0,10 limit 0, 10

 

Could anyone please help me with what I need to change here to correct the SQL syntax error?

Thanks

 

Mark

Link to comment
Share on other sites

it should read "order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);" (no quotes), MAX_DISPLAY_NEW_PRODUCTS is the number set in your admin.

 

all going on what you wrote below you have the limit in there twice twice

 

 

Hi Alex,

 

Thanks for that, I think we're getting close.

When I edited that code with your new code and tried out the new products page, it gave me this error on the page:

 

1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 0, 10' at line 1

 

select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from products p left join manufacturers m on (p.manufacturers_id = m.manufacturers_id), products_description pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' order by p.products_date_added DESC, pd.products_name Limit 0,10 limit 0, 10

 

Could anyone please help me with what I need to change here to correct the SQL syntax error?

Thanks

 

Mark

Link to comment
Share on other sites

Firstly set the SQL Statement back to its original setting and test to make sure that it displays all your products again. Once you have fixed this do the following:

 

The problem seems to be that the whole shop relies on the same function to sort the number

of pages and items. do the following to create your own (i've coded it for 10 items)

A long way round, but it works.

 

catalog/application_top.php

 

add:

 

require(DIR_WS_CLASSES . 'split_page_results2.php');

 

on line 432.

 

______________________

 

 

In catalog/products_new.php find line :

 

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

 

replace with:

 

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

 

______________________

 

 

 

Lastly create a file called "split_page_results2.php"

in the catalog/includes/classes directory.

 

The contents of the file is:

 

 

<?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 splitPageResults2 {

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

 

/* class constructor */

function splitPageResults2($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 = '10';

 

$this->number_of_pages = '1';

 

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

}

}

?>

Link to comment
Share on other sites

nice contribution. tnx!

 

one question: what do you change, if you want to see more new products (for example - 20).

 

I tried to change this ( $this->number_of_rows = '10'; )

into ($this->number_of_rows = '20';)

 

but all I got was displaying 1 to 10 (of 20 new products), but the display of them is the same. Still 10 displayed products, without new page for products 11-20. Tnx for help.

Link to comment
Share on other sites

nice contribution. tnx!

 

one question: what do you change, if you want to see more new products (for example - 20).

 

I tried to change this ( $this->number_of_rows = '10'; )

into ($this->number_of_rows = '20';)

 

but all I got was displaying 1 to 10 (of 20 new products), but the display of them is the same. Still 10 displayed products, without new page for products 11-20. Tnx for help.

 

I've made a few tweaks and posted it as a contribution. If you install the new version it adds the control variables into the admin section allowing you to easily change the number of products displayed:

 

Untitled-2.gif

Link to comment
Share on other sites

well, it works fine. Only the numbering display at the bottoms shows incorrectly. On pg1 it says: 1-10 of 10 items, on page 2 it says 11-20 of 10. Just for your info :)

 

tnx

 

I'm glad that it is coming in useful.

 

I have just posted an updated version of the contribution:

 

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

 

I have fixed the problem with the text at the bottom of the screen so that it should now display correctly. I have also tweaked how the products are displays. For example if you set the max products to 20, and the number of pages to 4, then you will get 5 products per page.

 

Please make sure however that the max number of products, divided by the number of pages equals a whole number as I haven't had time to counter the rounding issues that come from trying to get for example 20 products over 3 pages.

 

Hope that is useful

Link to comment
Share on other sites

  • 3 months later...
I'm glad that it is coming in useful.

 

I have just posted an updated version of the contribution:

 

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

 

I have fixed the problem with the text at the bottom of the screen so that it should now display correctly. I have also tweaked how the products are displays. For example if you set the max products to 20, and the number of pages to 4, then you will get 5 products per page.

 

Please make sure however that the max number of products, divided by the number of pages equals a whole number as I haven't had time to counter the rounding issues that come from trying to get for example 20 products over 3 pages.

 

Hope that is useful

 

 

I get this error when I try to run the code-

 

ERROR

 

SQL query:

 

INSERT INTO 'configuration'( 'configuration_title', 'configuration_key', 'configuration_value', 'configuration_group_id', 'configuration_description' )

VALUES (

'Custom Product Display, Maximum Pages', 'MAX_PAGES', '1', '3', 'Set the maximum results pages'

)

INSERT INTO 'configuration'( 'configuration_title', 'configuration_key', 'configuration_value', 'configuration_group_id', 'configuration_description' )

VALUES (

'Custom Product Display, Maximum Products', 'MAX_PRODUCTS', '10', '3', 'Set the maximum products per page'

)

 

MySQL said: Documentation

#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''configuration' ('configuration_title','configuration_key','con

 

 

Any help?

Link to comment
Share on other sites

  • 3 months later...
I get this error when I try to run the code-

 

ERROR

 

SQL query:

 

INSERT INTO 'configuration'( 'configuration_title', 'configuration_key', 'configuration_value', 'configuration_group_id', 'configuration_description' )

VALUES (

'Custom Product Display, Maximum Pages', 'MAX_PAGES', '1', '3', 'Set the maximum results pages'

)

INSERT INTO 'configuration'( 'configuration_title', 'configuration_key', 'configuration_value', 'configuration_group_id', 'configuration_description' )

VALUES (

'Custom Product Display, Maximum Products', 'MAX_PRODUCTS', '10', '3', 'Set the maximum products per page'

)

 

MySQL said: Documentation

#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''configuration' ('configuration_title','configuration_key','con

Any help?

 

 

 

Hi another newbie here - dun gone wrong again I think!

 

Trying to input contribution NewProductsV1.1 which would do just what I want if I can get it going.

 

Have run the code into my database but when I try to put the require in cat/inc/app.top I am getting an internal configuration error from the server.

 

so: 1. Is line 431 require(DIR_WS_FUNCTIONS . 'split_page_results.php'); & do I put the require for the class immediately after this? If this seems a strange question the answer is I can't get line numbers in my editor and it's not easy counting that many lines.

2. Should the relevant part of "configure" in the database look like this

 

(143, 'Custom Product Display, Maximum Pages', 'MAX_PAGES', '1', 'Set the maximum results pages', 3, NULL, NULL, '0000-00-00 00:00:00', NULL, NULL),

(144, 'Custom Product Display, Maximum Pages', 'MAX_PAGES', '1', 'Set the maximum results pages', 3, NULL, NULL, '0000-00-00 00:00:00', NULL, NULL);

 

It seems to me I may have inserted the same line twice but as a complete newbie to this I am not sure.

 

If I have entered the same line twice can I simply insert the second line and ignore the double entry(if it is one) or do I have to delete line 144 before entering the line I should have put in - AND how do I delete that line if I need to?

 

Confused? You will be! - just watch the next episode of "newbie".

 

Thanks in advance to anyone who can point me in the right direction - I would be most grateful.

 

Ann.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...