Jump to content

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?

Link to comment
https://forums.phpfreaks.com/topic/501-where-and-or/
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.

Link to comment
https://forums.phpfreaks.com/topic/501-where-and-or/#findComment-1704
Share on other sites

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.