kahodges Posted March 11, 2010 Share Posted March 11, 2010 I am having some trouble getting the code below to pull dates from a database and echo: mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT nickname, last_name, date_format(BirthDate,"%m/%d/%Y"), QuitDate FROM employees WHERE QuitDate is null AND MONTH(BirthDate) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH));"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td></td> <td></td> <td></td> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"nickname"); $f2=mysql_result($result,$i,"last_name"); $f3=mysql_result($result,$i,"date_format(BirthDate,"%m/%d/%Y")"); ?> It throws the error: Parse error: syntax error, unexpected '%'. But, the above query is valid and works in phpMyAdmin. Any help would be appreciated. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 11, 2010 Share Posted March 11, 2010 "date_format(BirthDate,"%m/%d/%Y")" ^- start string ^- end string ^- start string ^- end string What you have is a MySQL string enclosed in a PHP string. When you start doing these types of things you have to be careful of how you nest strings. Either of these might work: "date_format(BirthDate,\"%m/%d/%Y\")" 'date_format(BirthDate,"%m/%d/%Y")' Taking it further, your original code is exactly the same, syntactically, as if you had typed: "string1" %m/%d/%Y "string2" Which is not valid PHP code. Quote Link to comment Share on other sites More sharing options...
kahodges Posted March 11, 2010 Author Share Posted March 11, 2010 That helped me so much. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.