SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    advanced searcg perfect query

    hi ppl
    i am facing this problem with searching u know i want to allow users to write inside the seaching text box several values to serch for
    like

    searching for countries:
    -----------------
    USA , Brazil ; UK
    -----------------
    see the users should write many valeus and the seperate is just a comma or a semi so how iam goin to adapt this with my query maybe i should strip the value comming from the form

    what do u think any ideas

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $search "USA, UK, France";
    $search explode(","$search);

    $sql "SELECT * FROM your_table WHERE";
    $sql .= " (1>2";
    for(
    $i=0$i<count($search); $i++)
    {
      if(
    $search[$i] != "")
      {
        
    $where .= " OR Country LIKE '%".trim($search[$i])."%'";
      }
    }
    $sql .= ")"
    Maybe something like this will help.
    Also make a note bellow search field that they can enter comma separated values.
    This is just an idea though.
    -- Jelena --

  3. #3
    SitePoint Evangelist nsj's Avatar
    Join Date
    Oct 2005
    Location
    Jamaica (W.I)
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OR you could do a FULLTEXT search.
    Read up on MATCH AGAINST.
    This feature returns search relevance and other fancy stuff.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hay guys sorry but these codes aint enough for me thanks for the help .
    what i neeed is :
    1- strip the variable from all the speciall character else than the , or ;
    2- explode the variable to make it as an array and then take every block add it to the query

    what if the user wrote just commas in the text box like this : ,,,,,,,,,,,,,,,,,,,,,,,,,
    i tried it and it broke the hell out of my query
    so i have to check also that the variable does includes strings else than special chars ??????
    getting complicated right..

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face

    Forums are to provide help not to do all the work for you, jelenas code should be enough for you to workout how you need to tackle this problem. Programming is about solving problems. At least have a go at writing a script using jelenas code before you reply saying you cant do it.

  6. #6
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by infinityinteract
    Forums are to provide help not to do all the work for you, jelenas code should be enough for you to workout how you need to tackle this problem. Programming is about solving problems. At least have a go at writing a script using jelenas code before you reply saying you cant do it.
    Ok, don't be so hard on him. But you are partly right. This forum has plenty of threads on this topic disccussed before, so I would suggest him to search a little bit.

    haidoura, I'm not sure how come my code didn't help you?
    -- Jelena --


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
  •