Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

date function is not returning correct value

New Here ,
Aug 21, 2009 Aug 21, 2009

I have used the following code to display only the value for last seven days. it works fine in homepage(www.dealfindit.com)  but in other page like category(www.dealfindit.com and click MP3 )

SELECT title, merchant, image, price, price_price, dollar_sign, click_here, listprice_text, dealexpire_text, added_text, to_shop, price_note, description, link_product, shipping_info, tax_info, other_info, deal_expire, list_price, category_items, buying_instruction, DATE_FORMAT(date_created, '%m/%d/%Y %l:%i %p') AS 'date_created_alias',DATE_FORMAT(date_created,'%W %M %d %Y') AS 'date_only'
FROM mylist
WHERE date_created > SUBDATE(NOW(), 7)
ORDER BY date_created DESC

code for category page

======================

SELECT title, merchant, image, price, price_price, dollar_sign, click_here, listprice_text, dealexpire_text, added_text, to_shop, price_note, description, link_product, shipping_info, tax_info, other_info, deal_expire, list_price, category_items, sub_category, buying_instruction, DATE_FORMAT(date_created, '%m/%d/%Y %l:%i %p') AS 'date_created_alias',DATE_FORMAT(date_created,'%W %M %d %Y') AS 'date_only'
FROM mylist
WHERE date_created > SUBDATE(NOW(), 7) AND title LIKE '%colname%' OR sub_category  LIKE '%colname%' OR category_items LIKE '%colname%'
ORDER BY date_created DESC

TOPICS
Server side applications
538
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 21, 2009 Aug 21, 2009

When combining AND with OR's in your where clause, be careful  of order of operations. In your case, you probably want to add parenthesis:

WHERE date_created > SUBDATE(NOW(), 7) AND (title LIKE '%colname%' OR sub_category  LIKE '%colname%' OR category_items LIKE '%colname%')
Translate
LEGEND ,
Aug 21, 2009 Aug 21, 2009
LATEST

When combining AND with OR's in your where clause, be careful  of order of operations. In your case, you probably want to add parenthesis:

WHERE date_created > SUBDATE(NOW(), 7) AND (title LIKE '%colname%' OR sub_category  LIKE '%colname%' OR category_items LIKE '%colname%')
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines