Jump to content

Recommended Posts

Hey guys,

 

I'm getting pretty frustrated with this now, I am trying to select products from a table that are in the future only (items that haven't expired) but all the date comparison's I try just seem to return the past dated items as well as future items.

 

SELECT `item_id`,`item_name`,`item_owner`,`item_condition`,`item_price`,`item_end_time`,xxxxxxxxx_school.school_name FROM `xxxxxxxxxxx_item` LEFT JOIN `xxxxxxxxxx_school` ON `school2school_item`.`item_owner`=`xxxxxxxxx_school`.`school_id` WHERE `item_name` LIKE '%mac%' OR `item_description` LIKE '%mac%' AND `item_end_time` > '2010-03-25 09:30:43'  ORDER BY `item_end_time` ASC LIMIT 0,5;

 

I was asked to hide the company name, but thats the query that I'm trying to write/run, I've tried using UNIX_TIMESTAMP() and checked the data types on the datetime field (item_end_time) but it always returns dates that have been and gone.

 

Any idea's anyone?

Link to comment
https://forums.phpfreaks.com/topic/196461-mysql-date-comparison/
Share on other sites

Your WHERE clause contains a logical OR. What do we know about a TRUE value OR'ed with anything? It is TRUE.

 

You need to use () in your logical statement to force the Operator Precedence that you want. I'll guess you actually want this for the WHERE part of the query -

 

WHERE (`item_name` LIKE '%mac%' OR `item_description` LIKE '%mac%') AND `item_end_time` > '2010-03-25 09:30:43'  

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.