results.php显示所有旧查询

时间:2015-04-09 13:22:10

标签: php mysql

我使用带有mysql的php创建了一个网站搜索栏,我的结果页面显示了所有旧查询。我甚至尝试从其他计算机和搜索查询仍然出现。我没有重复的关键字,所以不应该是一个问题。如何获取结果页面以转储旧查询?

<?php
        $input = $_GET['input'];//Note to self $input in the name of the search feild
        $terms = explode(" ", $input);
        $query = "SELECT * FROM search WHERE ";

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

        // connecting to our mysql database
        mysql_connect("localhost", "pti_user", "policetech1");
        mysql_select_db("pti_db");

        $query = mysql_query($query);
        $numrows = mysql_num_rows($query);
        if ($numrows > 0){

            while ($row = mysql_fetch_assoc($query)){
                $id = $row['id'];
                $title = $row['title'];
                $description = $row['description'];
                $keywords = $row['keywords'];
                $link = $row['link'];
                echo "<h2><a href='$link'>$title</a></h2>
                $description<br /><br />";

            }

        }

        else

            echo "No results found for \"<b>$input</b>\"";

        // disconnect
        mysql_close();
    ?>

0 个答案:

没有答案