Jump to content


Photo

WHERE / AND/ OR


  • Please log in to reply
2 replies to this topic

#1 cK

cK
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 23 May 2003 - 03:40 PM


	$query = "SELECT * FROM test WHERE (TO_DAYS(NOW()) - TO_DAYS(timestamp)) < days_valid and category_id=\'$category[id]\' or category_id=\'9\' ORDER BY timestamp DESC LIMIT $pager->offset,$pager->limit";

	$result = mysql_query($query) or error ("Unable to connect to SQL server. Try again later.");


Will the above query give all valid (=still public) results from category $category[id] or category 9 ?

I\'m not sure how to write it; first and or first or? with () or without?

#2 barbatruc

barbatruc
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationMontreal, Quebec, Canada

Posted 26 May 2003 - 12:53 PM

according to your query, it will select everything from test that has a specific id and not older than a certain number of days OR everything in category #9 (no matter how old its content is). Is this what you want?

You should try this; it will ensure all content is not older than a certain number of days, but might be coming from a specific category or from category #9:
$query = "SELECT * FROM test WHERE (TO_DAYS(NOW()) - TO_DAYS (timestamp)) < days_valid AND (category_id=\'$category[id]\' or category_id=\'9\') ORDER BY timestamp DESC LIMIT $pager->offset,$pager->limit";

// notice the use of ( and ) for the OR operator...
Use need to know how to use logical operators... This might help:
http://java.sun.com/...ts/bitwise.html

JP.
Unfortunately, PHP \'empowered every moron with a copy of Windows notepad to be \"web programmers\". (...) Give PHP a real INFRASTRUCTURE. Use PEAR!!!\'

#3 cK

cK
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 26 May 2003 - 05:08 PM

THANKS !!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users