Hi all,
I have search through the forums and tutorial! They are plenty of similar topics, but it is not the answers to my problem.
Well, I have seen lots of websites giving search for their database. Like searching for hotel or restaurants etc..
Lets say, I would like to search with some terms in the result to get fewer results that match my desires more precisely. I will first create a search form with some select options like below.
1. Type keywords
2. Select locations
3. Select what kinds of restarant / how many stars hotels.
4. Select prices less or greater then.
....... can be added more later.
My question is, how to search within the results of a mysql query with php? I have understand how to create tables, but how many tables I should create in my MySQL DB to store the above data? And I want the users to select at least one option.
I just need some Ideas on how to do this. Or maybe any criteria terms or keywords I can search for this. Or if you had any code would like to share please post a reply or email to me.
Many thanks in advance~
How to sort search with some terms from database?
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Searching with multiple fields was talked about very recently, so I'm not going to talk about that. Instead, I'll talk a little about sub-searching.. The basics are: you store all the information you require to recreate the current search. This storage can be through hidden fields, or through session data. Once you figure out the initial search, a subsearching ability isn't too far away.. just need some special processing to combine any terms that need it..
Hi feyd~
Thanks for your prompt attention to my question.
Anyway, I still have not create form, code either, because I'm still gathering some info and ideas of doing this. And I shoudn't make excuseses for myself as telling I'm a newbie. Well, still have to do lots of home work
!
Well, I have been spending some times to understand the String Comparison Functions. But I just quite don't understand how to narrow down the search for the best result.
Please correct me if my ideas gone wrong.
Firstly, I should create a form to gather what the users had post of selecting for the search. And I would name each input as below;
1. keyword for keywords search
2. option1 for location
3. option2 for type of cuisine
4. option3 for prices.
When the user submit the search, then my query should be like this;
SELECT * FROM table WHERE keyword LIKE '%keyword%' AND location LIKE '%option1%' AND type_cuisine LIKE '%option2' AND prices LIKE '%option3%';
Is this how I search through the database? Please correct me if I'm wrong. If the above query is possible, I just don't understand how they sort the results?
For example I have 2 rows of data in my table structure.
---------------------------------------
| location | type_cuisine | prices |
---------------------------------------
| Place 1 | THAI | 100 |
| Place 1 | JAPANESE | 100 |
----------------------------------------
If I searches place 1 for option1 and Japanese food for options 3.
Will the searched for best result is to be the 2nd row. Or it just had the 1st row and 2nd row for result because the option 1 matches the same location?
Hope to hear from any advise. Many thnaks in advance~
Thanks for your prompt attention to my question.
Anyway, I still have not create form, code either, because I'm still gathering some info and ideas of doing this. And I shoudn't make excuseses for myself as telling I'm a newbie. Well, still have to do lots of home work
Well, I have been spending some times to understand the String Comparison Functions. But I just quite don't understand how to narrow down the search for the best result.
Please correct me if my ideas gone wrong.
Firstly, I should create a form to gather what the users had post of selecting for the search. And I would name each input as below;
1. keyword for keywords search
2. option1 for location
3. option2 for type of cuisine
4. option3 for prices.
When the user submit the search, then my query should be like this;
SELECT * FROM table WHERE keyword LIKE '%keyword%' AND location LIKE '%option1%' AND type_cuisine LIKE '%option2' AND prices LIKE '%option3%';
Is this how I search through the database? Please correct me if I'm wrong. If the above query is possible, I just don't understand how they sort the results?
For example I have 2 rows of data in my table structure.
---------------------------------------
| location | type_cuisine | prices |
---------------------------------------
| Place 1 | THAI | 100 |
| Place 1 | JAPANESE | 100 |
----------------------------------------
If I searches place 1 for option1 and Japanese food for options 3.
Will the searched for best result is to be the 2nd row. Or it just had the 1st row and 2nd row for result because the option 1 matches the same location?
Hope to hear from any advise. Many thnaks in advance~
OK, now that is actually my keyword search had a drawback which is only search the first column and not the entire table structured. Am I right? So, i needed to do with boolean addictions or wildcarding.feyd wrote:your query's keyword search will need a like for each keyword.. with boolean additions and wildcarding, if needed.
Well, actually I'm quite not understand how to do this. For my understanding, first I have to separate the keyword search query with other options. Secondly, write a query which make all the input fields to have a LIKE '%".$keyword."%' .
Ok, I will try to do some search again on this. Will come back later if I get the code. Thanks feyd!
OK, now I have a table structured like below;
keyword | body | location | prices | id |
And I have this code for keyword matches to a string,
$query_result = "SELECT * FROM table WHERE MATCH(keyword, body) AGAINST ('$keyword') ORDER BY id DESC";
My final question is how to adapt a boolean search narrow down the result in addictional options? Such as select option.
keyword | body | location | prices | id |
And I have this code for keyword matches to a string,
$query_result = "SELECT * FROM table WHERE MATCH(keyword, body) AGAINST ('$keyword') ORDER BY id DESC";
My final question is how to adapt a boolean search narrow down the result in addictional options? Such as select option.