[Done v1.3.9a] New Products... results in SQL Error
Running Zen Cart 1.3.8a
Database Patch Level: 1.3.8
PHP 4.4.9
From the Admin page, in Tool->Layout Boxes Controller, I have "sideboxes/whats_new.php" turned OFF
From Configuration->New Listing, I have "Mask Upcoming Products from being include as New Products" set to 1.
The "New Products..." link in my Categories sidebox results in a SQL error. I expected a page with no new products displayed.
This can be seen at http://chessieshop.tracefork.com/
Is this a bug, or am I configured illegally?
Any help would be appreciated. I would be satisfied with hiding the "New Products..." link in the Categories sidebox.
Lars
The sql error is:
"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 '-0, 0' at line 11
in:
[SELECT p.products_id, p.products_type, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name, p.products_model, p.products_quantity, p.products_weight, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status, p.master_categories_id 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 and (p.products_date_available <=20080925 or p.products_date_available IS NULL) order by p.products_date_added DESC, pd.products_name limit -0, 0]"
Re: New Products... results in SQL Error
Sounds like you have the Maximum Values set to 0 ...
Re: New Products... results in SQL Error
Quote:
Originally Posted by
Ajeh
Sounds like you have the Maximum Values set to 0 ...
Thank you, that was the problem.
Lars
Re: New Products... results in SQL Error
Thanks for the update that having the Maximum Value of 0 will cause SQL errors or division by 0 errors ... :smile:
Re: New Products... results in SQL Error
Problem:
"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 '-0, 0' at line 11"
This can also result in PCI scans failing.
Cause:
If you set any of the Admin->Configuration->Maximum Values to zero, the above situation may occur.
Fix:
There are a few ways to avert this situation:
a) Don't set Maximum Value settings to 0.
b) Change /includes/classes/split_page_results.php to detect 0 values and assign something different if that happens:
At line 25 find this section, and insert the new line as highlighted:
Code:
/* class constructor */
function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page', $debug = false) {
global $db;
$max_rows = ($max_rows == '' || $max_rows == 0) ? 20 : $max_rows;
$this->sql_query = $query;
$this->page_name = $page_holder;
c) Change /includes/classes/split_page_results.php to handle the "-0" situation more gracefully if it ever occurs:
At line 84, find this:
Code:
// fix offset error on some versions
if ($offset < 0) { $offset = 0; }
$this->sql_query .= " limit " . $offset . ", " . $this->number_of_rows_per_page;
}
and change it to this:
Code:
// fix offset error on some versions
if ($offset <= 0) { $offset = 0; }
$this->sql_query .= " limit " . ($offset > 0 ? $offset . ", " : '') . $this->number_of_rows_per_page;
}
I recommend all three :blush:
Re: [Done v1.3.9] New Products... results in SQL Error
Just an FYI, I may be wrong, but...
I believe this only error only occurs w/ PHP4.x or below. I'm on 5.x and just tried applying this patch and it actually CAUSED the error to occur on my site. I simply took out the code and it was fixed.
Re: [Done v1.3.9] New Products... results in SQL Error
Actually, the "fix" was initially developed when using MySQL 5, and then tested again on MySQL 4 before posting.