listman100 Posted April 21, 2007 Share Posted April 21, 2007 Hi I'm trying to use a MySQL "CASE" statement within PHP to develop a conditional query. The query runs fine within from the MySQL command prompt with the "case" statements. And the PHP code works fine when I remove the lines that begin with "case". However when I run the query as listed below within my PHP code i get the following: [Fri Apr 20 22:15:24 2007] [error] [client 10.188.50.74] PHP Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /srv/www/htdocs/mysql-learn/acetrack-post.php on line 68, referer: http://webserver1/mysql-learn/acetrack-post.html < code snip > $query =" SELECT acetitle, tracking_no, aceamt, case when (To_days(curdate()) - To_days(create_date)) >= 90 Then pototalamt else "" end as "90past" , case when (To_days(curdate()) - To_days(create_date)) < 90 and (To_days(curdate()) - To_days(create_date)) > 30 Then pototalamt else "" end as "30-90past" FROM Purtable t LEFT JOIN acelog a ON ace=acenum WHERE ace='0220' GROUP by po ASC "; $result = mysql_query($query); < /code snip > Thanks in advance for any help. Link to comment https://forums.phpfreaks.com/topic/47980-solved-mysql-case-statement-within-php-syntax-or-correct-quoting/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.