I'm having trouble with the logic for my query. Printing $sql gives me the following:
SELECT r.id,r.created,r.firstname,r.lastname,r.address1,r.city,r.state,r.zip,r.phone,r.email,r.comments,Error: 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 'BBQ' at line 1
"BBQ" is the first $val from the loop. What am I missing?
$sql = "SELECT r.id,r.created,r.firstname,r.lastname,r.address1,r.city,r.state,r.zip,r.phone,r.email,r.comments,";
$dbQuery = mysql_result(mysql_query("SELECT description FROM events"), 0,0);
$size = count($dbQuery);
$i = 0;
foreach ($dbQuery as $val)
{ //02
if($val != '')
{ //02
$sql .= "MAX(CASE e.description WHEN '". $val ."' THEN e.description END) AS `". $val ."`";
}
$i++;
if($i != $size) $sql .= ",";
}//02
if (!mysql_query($dbQuery)) {
die('Error: ' . mysql_error());
}
$sql .= "FROM requests r
LEFT OUTER JOIN (
registration_xref xref
INNER JOIN events e ON e.id_events = xref.event_id
) ON r.id = xref.attendee_id
GROUP BY r.id";