laPistola Posted November 12, 2011 Share Posted November 12, 2011 MYSQL: 5.1 Hello This is the line of code "SELECT * FROM news WHERE (show >= ".$tdate." AND expire < ".$tdate.") OR (show = 00000000 AND expire < ".$tdate.") AND (show = 00000000 AND expire = 00000000) ORDER BY `order`, title ASC" The error is 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 'show >= 20111112 AND expire < 20111112) OR (show = 00000000 AND expire < 2011111' at line 1 show and expire are both date fields in the DB, $tdate is todays date in the format yyyymmdd Generally I need the record to show if both show and expire = 00000000, If show is of the days date or the date has pasted AND it hasn't gone past the expire date. Also I need the records to show if either date = 00000000 and there show on or expire condition is true. I have gone through many of websites, looked at examples and can't see where my issue is. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/250996-problem-with-where-clause/ Share on other sites More sharing options...
Pikachu2000 Posted November 12, 2011 Share Posted November 12, 2011 Show is a MySQL reserved word. EDIT: URL corrected . . . Link to comment https://forums.phpfreaks.com/topic/250996-problem-with-where-clause/#findComment-1287600 Share on other sites More sharing options...
jasonc Posted November 12, 2011 Share Posted November 12, 2011 try the following as see if you get the same error EDITED "SELECT * FROM `news` WHERE (`show` >= ".$tdate." AND `expire` < ".$tdate.") OR (`show` = '00000000' AND `expire` < ".$tdate.") AND (`show` = '00000000' AND `expire` = '00000000') ORDER BY `order`, `title` ASC" Link to comment https://forums.phpfreaks.com/topic/250996-problem-with-where-clause/#findComment-1287605 Share on other sites More sharing options...
laPistola Posted November 12, 2011 Author Share Posted November 12, 2011 Quote Show is a MySQL reserved word. Ah thanks! Link to comment https://forums.phpfreaks.com/topic/250996-problem-with-where-clause/#findComment-1287607 Share on other sites More sharing options...
laPistola Posted November 12, 2011 Author Share Posted November 12, 2011 Quote try the following as see if you get the same error EDITED "SELECT * FROM `news` WHERE (`show` >= ".$tdate." AND `expire` < ".$tdate.") OR (`show` = '00000000' AND `expire` < ".$tdate.") AND (`show` = '00000000' AND `expire` = '00000000') ORDER BY `order`, `title` ASC" News isn't a reserved word as well is it?? It works without me exiting the word news. Thanks anyway! Link to comment https://forums.phpfreaks.com/topic/250996-problem-with-where-clause/#findComment-1287609 Share on other sites More sharing options...
Pikachu2000 Posted November 12, 2011 Share Posted November 12, 2011 I fixed the link to MySQL's reserved words manual page in my reply above . . . Link to comment https://forums.phpfreaks.com/topic/250996-problem-with-where-clause/#findComment-1287614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.