cK Posted May 23, 2003 Share Posted May 23, 2003 $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? Link to comment https://forums.phpfreaks.com/topic/501-where-and-or/ Share on other sites More sharing options...
barbatruc Posted May 26, 2003 Share Posted May 26, 2003 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/docs/books/tutorial/ja...ts/bitwise.html JP. Link to comment https://forums.phpfreaks.com/topic/501-where-and-or/#findComment-1704 Share on other sites More sharing options...
cK Posted May 26, 2003 Author Share Posted May 26, 2003 THANKS !!! Link to comment https://forums.phpfreaks.com/topic/501-where-and-or/#findComment-1708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.