mysql php搜索引擎查询多列

So i am currently messing around creating a search engine just out of interest and was curious if i was able to query more than just the keyword column in the mysql database. At the moment i am able to search for somthing and get the results based off of my "keyword" column. But if the word or phrase i am searching not within the keyword column but it is found in the title column or description column is it possible for it to show up because it found it within those columns aswell?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Search Engine - Search</title>
</head>
<body>

    <h2>Search Engine</h2>
    <form action='./search.php' method='get'>
        <input type='text' name='k' size='50' value='<?php echo $_GET['k']; ?>' />
        <input type='submit' value='Search'>
    </form>
    <hr />
    <?php
        $k = $_GET['k'];
        $terms = explode(" ", $k);
        $query = "SELECT * FROM databeast WHERE ";

        foreach ($terms as $each){
            $i++;
            if ($i == 1)
                $query .= "keywords LIKE '%$each%' ";
            else
                $query .= "OR keywords LIKE '%$each%' ";
        }

        //connect
        mysql_connect("localhost", "username", "password");
        mysql_select_db("fapster") or die(mysql_error());

        $query = mysql_query($query);
        $numrows = mysql_num_rows($query);
        if ($numrows > 0) {
            while ($row = mysql_fetch_assoc($query)){
                $url = $row['url'];
                $title = $row['title'];
                $keywords = $row['keywords'];

                echo "<h1><a href='$url'>$title</a></h1>
                $keywords<br /><br />";
            }
        }

    ?>
</body>
</html>

Thanks in advance

I suggest you check into MySQL Full-Text search. http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html.

This allows you to search multiple keywords in a query. Plus, Full-Text gives you the benefit of actually understanding the words as "natural language" (so it deals with "stop words", "plurals" and "word stemming"). See http://dev.mysql.com/doc/refman/5.0/en/fulltext-query-expansion.html

Don't throw out the "Like" logic. MySQL Full-Text search has a few annoying things - so you may still want to use that logic. Here they are:

  1. Searches which return "too many" (%50 or greater) results return nothing. Not what a searcher usually expects, right? Normally people want it to work like Google does.
  2. Searches on words which are too short return nothing (see ft_min_word_len in /etc/my.sql)

Usually I combine the full text search with the like or "or" search and then ORDER by full text rank.

p.s. you'r script is vulnerable with SQL injection. Don't release onto Internet before reviewing.