Syntax Error Debug – Unexpected T_CONSTANT_ENCAPSED_STRING [closed]-Collection of common programming errors
Trying to pull off a histogram of Quote Values in a shopping cart. This query works if I paste it directly into mySQL, however I am having problems with the PHP side of things.
Error message:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in .../.../... Line 26.
My code:
echo '
Histogram of Quotes
'; $sql = 'SELECT ROUND(ROUND(Fixes.FixAM/31.1035 * Products.Fineness * Products.Buy * Quotes.Weight, 2), -3) AS bucket, COUNT(*) AS Count, RPAD('', LN(COUNT(ROUND(Fixes.FixAM/31.1035 * Products.Fineness * Products.Buy * Quotes.Weight, 2))), "*") AS bar FROM Quotes, Products, Fixes, Currencies, Metals, ProductTypes WHERE Quotes.ProductId = Products.Id AND Products.MetalId = Metals.Id AND Products.ProductTypeId = ProductTypes.Id AND Fixes.CurrencyId = Currencies.Id AND Fixes.MetalId = Metals.Id AND Currencies.Code = "GBP" GROUP BY bucket'; $stmt = $db->prepare($sql); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
Line 26 is the line which says
GROUP BY bucket';
PROOF that SQL Code Works
bucket COUNT bar
0 114 *****
1000 37 ****
2000 8 **
3000 2 *
4000 3 *
5000 4 *
8000 1
9000 1
10000 1
21000 1