My PHP search engine
<p>I am building a search engine. </p>

<p>I have written a basic crawler which scans the link of a given url and stores all the words it finds in the web page in a mysql database. i then proceeded to write a client which selected data from database based on the word input and it was ranked by the frequency of the word in the different urls. </p>

<p>The main problem I am facing is multiple terms. I am trying to put my keywords into an array. The thing is though it doesn't seem to be working.</p>

<p>I have designed search engines before that select only links + titles from a MYSQL database, without scanning the entire web page, and have had those work on multiple term search by array. What am I doing wrong.</p>

<p><em>The code from my previous search engine regarding multiple term search</em></p>

<pre><code>                $query = " SELECT * FROM scan WHERE "; 

    $terms = array_map('mysql_real_escape_string', $terms);
    $i = 0; 
    foreach ($terms as $each) {
          if ($i++ !== 0){
                $query .= " AND "; 
          }
          $query .= "keywords LIKE '%{$each}%'";
    }
    // Don't append the ORDER BY until after the loop
    $query .= "ORDER BY rank";
</code></pre>

<p><em>My code for the current search engine</em></p>

<pre><code>            if( isset($_POST['keyword']) ){
$k = $_POST['keyword'];
     }else{
$k = '';
         }
        $k = ( isset($_POST['keyword']) )? trim($_POST['keyword']) : '';
        $terms = (strlen($k) &gt; 0)? explode(' ', $k) : Array();
              $keyword = addslashes($term);
         $results = addslashes( $_POST['results'] );

       /* Execute the query that performs the actual search in the DB: */
            $result = mysql_query(" SELECT p.page_url AS url,
                       COUNT(*) AS occurrences 
                       FROM page p, word w, occurrence o
                       WHERE p.page_id = o.page_id AND
                       w.word_id = o.word_id AND
                       w.word_word = \"$keyword\"
                       GROUP BY p.page_id
                       ORDER BY occurrences DESC
                       LIMIT $results" );
</code></pre>
