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
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"

Link to comment
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"

 

News isn't a reserved word as well is it?? It works without me exiting the word news. Thanks anyway!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.