Jump to content

is it possible... php/mysql WHERE, AND, OR


monkeytooth

Recommended Posts

Is it possible to create a query that works like WHERE="%query string%" but not only that have AND OR clauses in it? A project I am working on I want to make a browse by category type of option. Only thing is the category that the user will click on could be up to 3 or 4 individual categories by themselves. But at the same time I need to apply the idea of %string% to it, to me it sounds far fetched, but I am looking for opinions and ideas as to whether maybe I can actually do something like that.

Link to comment
https://forums.phpfreaks.com/topic/193380-is-it-possible-phpmysql-where-and-or/
Share on other sites

Well that concept I know of, havent had much of a need for that. I guess what I am looking for is it possible to make a

 

WHERE category='%art%' AND OR category='%photography%' AND OR category='%Architecture%'

 

I highly doubt that would be the structure of the query but I think thats the only way I can convey what I am thinking.. Is there a search I can do similar to an array function? where I can use something like

in_array()

 

I should also mention I am searching 4 million records+ I don't know if that helps any but I know its worth mentioning.

I wouldnt put AND OR together.. but thats the only way I could represent what I am trying to get across to what I am looking to do.

 

The keywords I am working with can either be there or not, along with other words in the keyword structure..

 

Philosophy

Social

Science

Business & Economics

Fiction & Literature Mathematic

sPolitics & Current Affairs

Computer Science & Technology

History

Medical

Psychology

Education and Teaching

Journalism

Performing Arts

Religion & Spirituality

Would be an example of the categories...

 

Now lets say I look up "Religion & Spirituality"

 

Parapsychology & New Age Spirituality
Christian Prayer & Spirituality
Spiritual Writings
Comparative Religion
Sociology & Religion
Psychology & Religion
Religion & Politics
Philosophy of Religion
History of Religion
Traditional Religions
Eastern Religions & Ethics
Survey of World Religions
African American Religion
African Religions
Introductory Religion
Women & Religion
Religion & Human Sexuality
Survey Of Eastern Religions
Religion Dictionaries
Other Eastern Religions
Other Religions
Eastern Religions/Eastern Philosophy for K-12
Science & Religion
Survey of Western Religions
Western Religions & Ethics
Other Religions for K-12

 

Those would be the result of individual searches.. the top 3 for "%Spiritual%" the rest for "%Religion%"

 

Now maybe im not familiar with the OR part of the SQL query like I think I am. But I know the AND statement would limit it to if the words are together in the same column during the search. But Im sure from what I am thinking about the OR that its going to return a column with one or the other, but not both if there is a case where both may come up, say like with other categories.

 

So that all said what I am trying to figure out is there a method of getting the 3 styles of results, AND, OR, with wildcard. Maybe I have a fools logic about this, if I do, please by all means let me know that my logic is upside down.. Only reason I am asking for this is I have over 4 million records already in place with no specific category. I am trying to device a logical query that can put some order to the chaos so to speak that is my existing database. I am searching Product Descriptions, which in a sense are like categories from the way the DB was laid out but not if that makes sense to anyone.

Archived

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

×
×
  • 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.