SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Shantra's Avatar
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Single or multible word search!

    Hi,
    I hope that someone can help me with this code. I am trying to search for some of the words in the database.
    Eks:
    The exact name is: "XT 600E"
    I would like to search for just: "xt" or "xt600"

    CODE

    Search page:
    Model: <input type=\"text\" name="modelsearch" value="">

    Result page:
    if ($modelsearch == "")
    {
    $modelsearch = 0;
    }
    $querystring = "SELECT * FROM homes WHERE ";
    $querystring = $querystring."(model >= '$modelsearch')";

    elseif ($key == "modelsearch")
    {
    //do not do anything further -- already handled
    }


    I know that my code is wrong but it works with numbers
    I did visit the php.net site and read something about arreys, but I don't understand how to use them.


    Thanks!!!
    Last edited by Shantra; Jul 8, 2001 at 10:07.

  2. #2
    SitePoint Enthusiast Ckeren's Avatar
    Join Date
    Jun 2001
    Location
    AU
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query_string = "select attribute from tbl_name where attribute='xt' || attribute ='XT 600E' || attribute='xt600'":

  3. #3
    SitePoint Addict Shantra's Avatar
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Ckeren
    $query_string = "select attribute from tbl_name where attribute='xt' || attribute ='XT 600E' || attribute='xt600'":
    But the XT... was only an example!
    It could be ANY word/words.

    Thanks

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all you have to understand something.

    For a computer to know that xt600 means XT 600E you have to program that in.

    So you'd write a script that checks to see if the first two characters are letters, then you'd separate them into a new variable, then you check and see if the last 3 are numbers, so on and so forth.

    Thats before you even query the database.

    As for the rest of the search

    Where Field like '%xt%'

    will return all rows with xt in it, regardless if it is xt600, or next

    % is the SQL wildcard figure and can be used with like statements to search a part of a field instead of the whole field.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  5. #5
    SitePoint Addict Shantra's Avatar
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does this work?

    Result page:
    if ($modelsearch == "")
    {
    $modelsearch = 0;
    }

    $querystring = "SELECT * FROM homes WHERE ";
    $querystring = %$querystring%."(model >= '$modelsearch')";

    elseif ($key == "modelsearch")
    {
    //do not do anything further -- already handled
    }


  6. #6
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    more like:



    PHP Code:

    if ($modelsearch == ""

    $modelsearch 0

    $querystring " SELECT * FROM homes WHERE model='%$modelsearch%' ";  
    elseif (
    $key == "modelsearch"

    //do not do anything further -- already handled 


    This will go in and get all the rows WHERE the column "model" has the text "$modelsearch" in it at all.


    Also, your if/then/else structure is incorrect.

    Probably need something more like:
    PHP Code:
    if ($modelsearch) { 
    $querystring " SELECT * FROM homes WHERE model='%$modelsearch%' ";  
    //execute sql statement and process results here
    } else { 
    //they didn't search, do normal stuff

    -Jeff Minard | jrm.cc - Battlefield 2 Stats


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •