473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

problem in advance search

25
I have search code that is below:

Expand|Select|Wrap|Line Numbers
  1. $term = $vbulletin->input->clean_gpc('r', 'term', TYPE_STR);
  2.     if ($term != ''){$term_db .= "AND f.field8 like '%$term%' OR f.field10 like '%$term%' OR f.field12 like '%$term%' OR f.field13 like '%$term%' OR f.field21 like '%$term%' "; }
The problem is:
The full text is "leonardo dicaprio"
If i search 'leo' or 'leonardo' or 'dicaprio' or 'leonardo dicaprio' is ok.
If change position or cut the words like if I search 'leo dicap' or dicaprio leonardo it won't show the result.

Can someone out there help me how to make it possible?
May 26 '10 #1
11 1588
code green
1,726 Expert 1GB
search 'leo dicap' or dicaprio leonardo it cant show the result
I had to do this. I did it by seperating the words using strtok, then searching on the word 'chunks' as I called them.
Then you need to decide whether both chunks or only one has to be a hit
May 26 '10 #2
amel86
25
@code green
sory code green, i not clear what you mean, can you give an example.sory, i new in php
May 26 '10 #3
code green
1,726 Expert 1GB
From the manual
strtok() splits a string into smaller strings (tokens), with each token being delimited by any character from token.
That is, if you have a string like "This is an example string" you could tokenize this string into its individual words
by using the space character as the token.
Then which each chunk issue a separate SELECT query
Expand|Select|Wrap|Line Numbers
  1. AND f.field8 like '%$chunk%
strtok() is one function I can never write free hand so again, example from the manual
Expand|Select|Wrap|Line Numbers
  1. string = "This is\tan example\nstring";
  2. /* Use tab and newline as tokenizing characters as well  */
  3. $tok = strtok($string, " \n\t");
  4.  
  5. while ($tok !== false) {
  6.     echo "Word=$tok<br />";
  7.     $tok = strtok(" \n\t");
  8. }
  9.  
If I can find my code I will post but I am sure it is too fragmented across multiple functions to be much use.
Pretty awful if I remember
May 26 '10 #4
amel86
25
i have use this function but it still not too smart search..
if i search it just read the first word.
May 26 '10 #5
code green
1,726 Expert 1GB
You can't mix AND and OR
Expand|Select|Wrap|Line Numbers
  1. AND f.field8 like '%$term%' OR f.field10 like '%$term%' OR f.field12 like '%$term%' OR f.field13 like '%$term%' OR f.field21 like '%$term%'
Brackets should be used
Expand|Select|Wrap|Line Numbers
  1. AND (f.field8 like '%$term%' 
  2. OR f.field10 like '%$term%' 
  3. OR f.field12 like '%$term%' 
  4. OR f.field13 like '%$term%' 
  5. OR f.field21 like '%$term%')
May 26 '10 #6
amel86
25
thanks code green, but the problem still same. do you have any idea to make the search result more smarter like os commerce (osc)
May 26 '10 #7
code green
1,726 Expert 1GB
I reckom I am smarter than OS commerce ;-)
Could you redfine the problem and post relevant code
May 26 '10 #8
amel86
25
Expand|Select|Wrap|Line Numbers
  1. $term = $vbulletin->input->clean_gpc('r', 'term', TYPE_STR);
  2.     if ($term != '')
  3.         {
  4.         $token = strtok($term, " ");    
  5.         $term_db .= "AND f.field8 like '%$token%'"; 
  6.         }
the problem is :

if i search 'melaka'
the result are :
- Seri Costa Hotel Melaka
- Phiten Shop (Mahkota Parade) - Melaka
- Melaka Batik House (Noor Alfa)
- Melaka Art Store

but if i search 'melaka art'
the result still same because of it keep 'melaka' value.
how if i want the result just show
- Melaka Art Store

can u help me?
May 26 '10 #9
code green
1,726 Expert 1GB
You need to use strtok() in a while loop as in the example I posted.
Then you can build up the query string in the while loop using OR, or query each part seperately
Expand|Select|Wrap|Line Numbers
  1. $term_db .= "AND f.field8 like'"; 
  2. $tok = strtok($string," ");
  3. $term_db .= "%$tok%".' OR '; 
  4.  
  5. while ($tok !== false) {
  6.         $tok = strtok($string," "); 
  7.         $term_db .= "%$tok%".' OR '; 
  8.  
May 26 '10 #10
amel86
25
hello code green,
i have try your code but my page appear blank. i cant use while method.can it possible to use 'for loop'? i have try 'for loop', that is no error but this method cant find any result.can you give me example if do in for loop?
May 27 '10 #11
amel86
25
hye...i already solve this problem by use this
Expand|Select|Wrap|Line Numbers
  1. $tok = strtok($term, " "); 
  2.                 while ($tok !== FALSE)
  3.                 {
  4.                   $toks[] = $tok;
  5.                   $tok = strtok(" ");
  6.                 }
  7.                 while (list($k,$v) = each($toks))
  8.                 {
  9.                  $term_db .= "AND f.field8 like '%$v%'"; 
  10.                 }
tq green code for your great idea!
May 27 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Adam Nørregaard | last post by:
Hi, I have this Mysql db: id int(11) autoincremement prim. key parentid int(11) ... etc .. (fields for a discussion board) When parentid=0 then it is a new thread, otherwise it is a...
1
by: nortelsale | last post by:
i have a site that allow people to post for sale, for rent info, I want to have advanced search function that can search all the posting (in my site) by zip code, and by certain miles say 10, 20...
1
by: aznach | last post by:
Hello! I have a shared hosting account at GrokThis.net and have a problem with the module order of the Python search path. I'd like to use django's svn trunk instead of the...
0
by: venugopalsripada | last post by:
Hi, I use imaplib to download emails from my AOL accounts. I have 6 accounts. I am recieving ('NO', ) as a return value for search(None, 'ALL') for one of the accounts while all other acocunts are...
10
by: jonathan184 | last post by:
Hi I tried getting this to work through dreamweaver but it did not. So i found a n example on the internet , i followed everything exactly the search script does not work. Could somebody help me...
3
by: Paul | last post by:
Hello, I'm having a CSS positioning problem and hope someone can help me out please? If you take a look at this test page: http://www.greenflagaward.org.uk/home/beta In Safari 3.0 and...
2
by: preeti13 | last post by:
hi friends please help me with my problem i have a code for search application it is searching one record from the data base at a time but i have so many records with that name but its not searching...
2
by: Mark | last post by:
Hi All, I am creating a music database for a friend and have run into a problem. Within the ALBUM table, I wanted to store the ARTIST_ID rather than the ARTIST_NAME. To do this, I intended to have...
2
by: ryan2345 | last post by:
Hi, I have made a search page in which the user enters the keywords to be searched separated with a comma. The code that i ve used works well but it is displaying the name of the user twice....
0
by: jaffarkazi | last post by:
Hi I have a search page. A user would select the search parameters from various textbox, dropdowns, etc. Now the user will click search and get a list of search results. This is available in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.