Page 1 of 1

SQL problems with COUNT

Posted: Mon Aug 18, 2003 8:29 am
by voidstate
Hi

I am trying to write a query which gets details from a products db, and also the number of associated options from a productoption db.

The SQL I have is like:

Code: Select all

$query = '	SELECT products.image_thumb, 
					products.name, 
					products.ordercode, 
					products.short_desc, 
					products.mrp_price, 
					products.bigfish_price, 
					COUNT(productoption.optionId) 
					FROM  products, productoption
					WHERE products.category = ' . $this->category . ' 
					AND productoption.productId = products.productId 
					ORDER BY ' . $sortBy  .'
					GROUP BY products.productId';
What am I doing wrong? MySQL is not really throwing an error which tells me anything, just:
Error: You have an error in your SQL syntax near '(productoption.optionId) FROM products, productoption WHERE produc'

Posted: Mon Aug 18, 2003 3:17 pm
by xisle
try using double quotes around the entire query and single quotes within.

Code: Select all

$query="SELECT * FROMĀ  products 
WHERE category = '{$val}'";

- xisle

Posted: Tue Aug 19, 2003 3:11 am
by voidstate
Thanks for the reply, but the problem was solved when I removed the space between count and the first bracket.

Gah! I hate coding sometimes!

:roll: