SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Search database

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search database

    Is there a way to search a database for keywords?

    something like:
    PHP Code:
    return mysql_query("SELECT * FROM table WHERE myFirstColumn contains $searchWord OR mySecondComumn contains $searchWord"); 

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Google mysql search tutorial find this site first.

    Simple example that answers your question, other sites found should help too.

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $sSQL 
    sprintf(
        
    "SELECT foo FROM table WHERE bar LIKE '%%%s%%' OR bar LIKE '%%%s%%' OR bar LIKE '%%%s%%'",
        
    mysql_real_escape_string($sKeyword),
        
    mysql_real_escape_string($sKeyword),
        
    mysql_real_escape_string($sKeyword)
    );
    # SELECT foo FROM table WHERE bar LIKE '%keyword%' OR bar LIKE '%keyword%' OR bar LIKE '%keyword%'
    ?>
    See MySQL LIKE.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •