Error in search code of php
<p>I want to search my database named phpsearch and column college and 
I am using an explode function to separate the terms with spacing and not commas.
I have a doubt regarding the i term as the error says i is not defined but I though php is a language where you don not have to specify datatypes not declare variable </p>

<p>the code is </p>

<pre><code>&lt;?php 
    $k = $_GET['k'];
    $terms = explode(" ",$k);
    $query = "SELECT * FROM colsearch WHERE ";
    foreach ($terms as $each)
    {
        $i++;
        if($i == 1)
        $query .= "college LIKE '%$each%' ";
        else
        $query .= "OR college LIKE '%$each%'";
    }

    mysql_connect("localhost","root","");
    mysql_select_db("phpsearch");
    $query = mysql_query($query);
    $numrows = mysql_num_rows($query);

    if($numrows&gt;0){
        while ($row = mysql_fetch_assoc($query))
        $id = $row ['id'];
        $college = $row ['college'];
        $govpriv = $row ['govpriv'];
        $description = $row ['description'];
    $departments = $row ['departments'];
        $fees = $row ['fees'];
        $location = $row ['location'];
        $facilities = $row ['facilities'];
        $fests = $row ['fests'];
        $placements = $row ['placements'];
        $link = $row ['link'];

        echo "&lt;h2&gt;&lt;a href = '$link'&gt;$college&lt;/a&gt;&lt;/h2&gt;$description&lt;br/&gt;&lt;br/&gt;";
    } else {
        echo "No results found for $k";
    }
    mysql_close();
?&gt;
</code></pre>

<p>What is the error? I tried all possible ways.</p>
