【问题标题】:php keyworks search do not worksphp keyworks搜索不起作用
【发布时间】:2016-11-11 11:22:26
【问题描述】:

我想使用我创建的搜索引擎检索数据库中的数据。

它将搜索关键字从 testeach.php 传递给 searchTitle.php。

这是我的测试 seach.php 代码

    >!DOCTYPE html>
    <html>
    <head><title></title>
    </head>
    <body>
    <form action="searchTitle.php" method="GET" class="formright">
                        <input  type="text" name="keywords" placeholder="Search">
                        <input type="submit" value="search">                                        
                        </form> 
    </body>
    </html>

这是我的 searchtitle.php,它传递了来自 testsearch 的关键字。

<? php
    require_once 'database_conn.php'

    //collect search title
    if(isset($_GET['keywords'])){

        $searchq = $_GET['keywords'];
        $searchq = preg_replace("#[^a-z]#i" , "", $searchq);

        $query = mysql_query("SELECT eventTitle FROM te_events where eventTitle LIKE '%searchq%'") or die("could not search!");

        $count = mysqli_num_rows($query);

        if($count==0){
            echo "<p>There was no search result!</p>\n";
        }
        else{
            while ($row = mysql_fetch_assoc($query)){
                $title = $row['eventTitle'];
                $id    = $row['eventID'];

                echo "<p>$title</p>\n";
            }
    }
    }
?>

但是,它显示了这个错误

没有搜索结果! \n"; } else{ while ($row = mysql_fetch_assoc($query)){ $title = $row['eventTitle']; $id = $row['eventID']; echo " $title

\n"; } } } ?>

我很确定我的数据库连接正常,并且我的代码中没有看到任何拼写错误。

谁能告诉我我的问题是什么?

【问题讨论】:

  • 这意味着 PHP 甚至没有运行。但是您提供的代码中有许多基本错误,例如&lt;? php 我预计会出现语法错误,几乎可以肯定您没有正确设置 PHP。

标签: php


【解决方案1】:

有一些错误

1)$query = mysql_query("SELECT * FROM countries",$connection) or die("无法搜索!");

在 mysql_query 中添加连接变量

请参考php文档中的语法

2) 您使用 $count = mysqli_num_rows($query); 获取原始数量,但您使用 mysql_num_rows 而不是 mysqli_num_rows

请检查php版本以及与mysql或mysqli兼容的版本 请检查它,因为这也可能导致该类型的问题

这个答案可能会对你有所帮助。

【讨论】:

    猜你喜欢
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 2014-04-05
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多