Results 1 to 5 of 5

Thread: PHP Search

  1. #1
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default PHP Search

    How is it i would code something so that it searches a database for words (basically a search bar)?
    Coming and going...
    Highers are getting the better of me

  2. #2
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    $sql = mysql_query( "SELECT * FROM `database` WHERE `fieldname` LIKE '%' . $search . '%' ");

    should work.

  3. #3
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Blob View Post
    $sql = mysql_query( "SELECT * FROM `database` WHERE `fieldname` LIKE '$search' ");

    should work.
    Thanks, Didnt know about the LIKE command

    +REP if i can..

    EDIT: Cant..
    Coming and going...
    Highers are getting the better of me

  4. #4
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    529
    Tokens
    0

    Default

    You don't need to use the %
    Plus if you want to search multiple fields use this:

    PHP Code:
    $sql mysql_query"SELECT * FROM `database` WHERE `fieldname` LIKE  $search OR `fieldname2` LIKE  $search OR `fieldname3` LIKE  $search"); 
    etc

  5. #5
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by RichardKnox View Post
    You don't need to use the %
    Plus if you want to search multiple fields use this:

    PHP Code:
    $sql mysql_query"SELECT * FROM `database` WHERE `fieldname` LIKE  $search OR `fieldname2` LIKE  $search OR `fieldname3` LIKE  $search"); 
    etc
    If you have % it allows to search for the search to ignore the leading characters and the characters following the search string.

    See

    http://www.weberdev.com/ViewArticle.php3?ArticleID=81

Posting Permissions

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