Keyword search box?

Discussion in 'PHP' started by le007, Oct 1, 2007.

  1. #1
    How can I have a keyword search box - that you can actually type in a word and search for associated results?
    Thanks
     
    le007, Oct 1, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Where is the content stored?
     
    nico_swd, Oct 1, 2007 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Its stored in a database - any example of code would be classic!
     
    le007, Oct 1, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I'll point you in the right direction, but you have to do the rest yourself. :D

    
    
    if (!empty($_REQUEST['keyword']))
    {
        $query = mysql_query("
            SELECT *
            FROM table_name
            WHERE field_name LIKE '%" . mysql_real_escape_string($_REQUEST['keyword']) . "%'
        ") OR die(mysql_error());
    
        while ($result = mysql_fetch_assoc($query))
        {
            echo $result['field_name'], "<br />\n";
        }
    
        if (!$result)
        {
            echo 'No results found';
        }
    }
    
    PHP:
     
    nico_swd, Oct 1, 2007 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Thats really class, thanks for that!!! I'll have a go!
     
    le007, Oct 1, 2007 IP
  6. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #6
    well, is their any code to search inside an array using $_GET OR POST?

    like we have 10 elements in an array: if we search a word of element a it will give us element a as result
     
    khan11, Oct 1, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    ^^ Please start your own thread for separate questions that don't have anything to do with the original topic.
     
    nico_swd, Oct 1, 2007 IP