Jump to content

Archived

This topic is now archived and is closed to further replies.

cK

WHERE / AND/ OR

Recommended Posts


$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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×

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.