Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

MYSQL problem


Jeremy at oddly enough

Recommended Posts

Hi, I'm new to all this, including php, and mysql. I'm running oscommerce on a server using MYSQL version 3.23.54. While running the program, it shows this:

 

1064 - You have an error in your SQL syntax near 'MAX_RANDOM_SELECT_NEW' at line 1

 

select products_id, products_image, products_tax_class_id, products_price from products where products_status = '1' order by products_date_added desc limit MAX_RANDOM_SELECT_NEW;

 

It seems to have a problem, perhaps with an undefined variable in the 'MAX_RANDOM_SELECT_NEW' portion. If I take that part out, and specify a number n, it will go ahead, showing the newest n products. Would this be a problem with an include somewhere?

 

Thanks, Jeremy

Link to comment
Share on other sites

Can you paste the code exactly? For example, if you use:

 

your_query = tep_db_query("select products_id, products_image, products_tax_class_id, products_price from products where products_status = '1' order by products_date_added desc limit MAX_RANDOM_SELECT_NEW");

 

that won't work....but if you do something like:

 

your_query = tep_db_query("select products_id, products_image, products_tax_class_id, products_price from products where products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);

 

that should work. If you present MAX_RANDOM_SELECT_NEW as a variable then it will pass a number through....however, if you present it as the number you want to limit (as I think you are doing) then mySQL doesn't understand how to limit the results to a word instead of a number. Give it a shot...

 

HTH,

-Chris

Chris Sullivan

Link to comment
Share on other sites

Here's an example of the stock code

 

 if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW))

 

With that, I get the syntax error, but if I change it to this

 

 if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit " . 5))

 

It will work, and in this particular case, put the 5 newest products in the new product box on the first page.

 

I've played around with the select command right in the mysql shell, seeing what works, and haven't been able to get it to work at all with the MAX_RAN... in there.

 

Thanks, Jeremy

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...