Jump to content

Problem with WHERE clause


laPistola

Recommended Posts

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

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"

  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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.