#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    hi,

    im working on a php/mysql driven site which requires me to have a search facility based on multiple keywords. I read the tutorial "quick and dirty search engine". What i want to know is :

    1. Is there any SQL query i could perform which could to almost the same thing ( i dont really need the accuracy ) ?

    2. Any other methods of achieving it ?

    Thanks in advance for any assistance ..

    Cheers,

    Kahthan
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Yes,
    You can acchieve that in different way.

    if you are using a multiple keyword search then

    first you should split the keywords.

    ie,
    Let us say,i am searching for "God Is Love".First what i should do is just split this values at space(" ").You can use explode funtion for that.

    i am writing an example here:

    <?php

    $keywords= "I LOVE MY JESUS";
    $pieces = explode (" ", $keywords);

    //This returns an array holding all keywords

    $count=count($pieces);
    //take count of the keywords.

    $query="SELECT * FROM tblname WHERE";

    //create a select query...

    if ($count==1){
    //only one keyword user entered
    $query.="LIKE '%$keywords%'";

    }elseif $count>=1{
    //More than one keywords..

    for($a=0;$a<$count;$a++){
    //loop through all the keywords and complete select statement.

    $query.="field LIKE '%$pieces[$a]%'";

    if $a != $count{
    //if it is last keyword then don't put OR in select statment.
    $query.="OR";
    }
    }
    }

    $result=mysql_query($query,$con);
    // Now issue a select query..

    //Query should be like
    //$query="SELECT * FROM tblname WHERE field LIKE '%I%' OR field LIKE '%LOVE%' OR field LIKE '%MY%' OR field LIKE '%JESUS%'";

    ?>


    One thing ,I have not tested above script.But you can impliment this logic.

    I hope this may help you to solve your multiple keyword search problem..

    Good Luck!!!












    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."




    [This message has been edited by Shiju Rajan (edited June 07, 2000).]
  4. #3
  5. No Profile Picture
    ads
    Guest
    Devshed Newbie (0 - 499 posts)
    I am new to search concept. As per my knowladge search should be available for both static web pages and in contents of database pages. Can you suggest me some site or can you give me code/example which shows how to perform both types of search?
    Thanks
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    15
    I'm also interested in such a search mechanism for static and dynamic content.

    Please keep me posted


    ------------------
    Good luck,
    Bas

    ------------------
    E-mail me at: b.vandermeijden@pecoma.nl
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    Thanks for the idea...i will attempt implementation now and see...will keep everyone posted on results..


    thanks,


    kahthan
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    hi,

    first of all i tried the above example and it doesnt work for the following reasons :

    1. mySQL only supports the like field properly on numerical coloums , which is stated in the manual, which is why most people get muck when they try it..

    2. This should work on multiple keywords on multiple fields but not on multiple keywords in a single TEXT field...

    any ideas ?

    cheers,

    kahthan
  12. #7
  13. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    kahthan,
    the above logic should work fine.i usually do this for searching a field.

    Just check the $query,when you click on search button.
    ie,

    print $query;

    if it is not coming properly,then that might be the reason you were not able to see the query results.



    1. mySQL only supports the like field properly on numerical coloums , which is stated in the manual, which is why most people get muck when they try it..

    i haven't seen that in manual."like" should work fine with text field also.If you have any doubt,then just write a very small script with "like" sql select statement.

    "select * from tblname where fieldname like '%a%' or fieldname like '%b%'"


    2.This should work on multiple keywords on multiple fields but not on multiple keywords in a single TEXT field...


    No,No ..Multiple keywords in a TEXT field will work fine.Just i tested that with mysql database..

    one question, Which version of mysql you are using?

    if you have any problem to sort it out this,then i will help you to run this script...






    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited June 07, 2000).]
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    Hey Shiju,
    Thanks for the help man, but i just managed to implement the QandD search engine in the DevShed PHP section..works fine now...i just need to optimize it... I will try your method again though since it spares me the task of indexing all incoming information ...

    thanks,

    kahthan
    colombo
    sri lanka

Similar Threads

  1. help with tables and wordwrapping
    By junkedBrian613 in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 05:42 PM
  2. Simple find and replace word search for a text file with php?
    By rabid lemming in forum PHP Development
    Replies: 4
    Last Post: February 1st, 2004, 09:37 PM
  3. How to read multiple line text file into a variable
    By gatewaycityca in forum Visual Basic Programming
    Replies: 4
    Last Post: January 29th, 2004, 12:26 PM
  4. Inserting from form to multiple tables
    By barth in forum MySQL Help
    Replies: 0
    Last Post: January 25th, 2004, 09:27 AM
  5. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 06:19 PM

IMN logo majestic logo threadwatch logo seochat tools logo