PHP搜索只显示一个结果?

时间:2013-11-26 16:04:46

标签: php mysql sql

有人可以帮助我吗,我有一个PHP搜索脚本(如下所示,周围有HTML),我想在必要时返回多个搜索结果,但目前还没有,我已经挣得足够了到目前为止,我迷失了......

<?php
                    if(isset($_POST['completedsearch']))
                    {
                            $term = $_POST['query'];
                            $mysql = mysql_connect("localhost","user","password");
                            mysql_select_db("hcsd");
                            $qu = mysql_query("SELECT * FROM Sheet1 WHERE COMPANY LIKE '%".mysql_real_escape_string($term)."%' OR LOCATION LIKE '%"$.mysql_real_escape_string($term)."%' OR KEYWORDS LIKE '%".mysql_real_escape_string($term)."%' OR PRODUCTSSERVICES LIKE '%".mysql_real_escape_string($term)."%' "); //selects the row that contains ANYTHING like the submitted string
                            echo "
                                            <table><tr><th>Name</th>
                                            <th>Location</th>
                                            <th>Products/Services</th></tr>
                                            ";
                            while($row = mysql_fetch_array($qu))
                                       {

                                            echo "<tr><td>";  
                                            echo $row['COMPANY'];
                                            echo "</td>";
                                            echo "<td>";
                                            echo $row['LOCATION'];
                                            echo "</td>";
                                            echo "<td>";
                                            echo $row['PRODUCTSSERVICES'];
                                            echo "</td></tr></table>";
                            }
                    }
            ?> 

通过搜索电视可以在www.healthcareservicesdirect.com上查看搜索,该电视应显示Sky&amp;处女,但截至目前,只显示天空

3 个答案:

答案 0 :(得分:0)

尝试

"SELECT * FROM Sheet1 WHERE COMPANY LIKE '%".mysql_real_escape_string($term)."%' OR LOCATION LIKE '%".mysql_real_escape_string($term)."%' OR KEYWORDS LIKE '%".mysql_real_escape_string($term)."%' OR PRODUCTSSERVICES LIKE '%".mysql_real_escape_string($term)."%'"

我注意到LOCATION LIKE '%"$.mysql_real_escape_string($term)."%'你有$

答案 1 :(得分:0)

我刚刚看了它,我看到它列出处女! 它只是不在表中,因为第一个条目是。它位于页面底部。 要解决这个问题,你必须将echo“”从while循环中删除,因为在第一次输入后你将关闭表格,所以你的代码应该是这样的:

<?php
                if(isset($_POST['completedsearch']))
                {
                        $term = $_POST['query'];
                        $mysql = mysql_connect("localhost","user","password");
                        mysql_select_db("hcsd");
                        $qu = mysql_query("SELECT * FROM Sheet1 WHERE COMPANY LIKE '%".mysql_real_escape_string($term)."%' OR LOCATION LIKE '%"$.mysql_real_escape_string($term)."%' OR KEYWORDS LIKE '%".mysql_real_escape_string($term)."%' OR PRODUCTSSERVICES LIKE '%".mysql_real_escape_string($term)."%' "); //selects the row that contains ANYTHING like the submitted string
                        echo "
                                        <table><tr><th>Name</th>
                                        <th>Location</th>
                                        <th>Products/Services</th></tr>
                                        ";
                        while($row = mysql_fetch_array($qu))
                                   {

                                        echo "<tr><td>";  
                                        echo $row['COMPANY'];
                                        echo "</td>";
                                        echo "<td>";
                                        echo $row['LOCATION'];
                                        echo "</td>";
                                        echo "<td>";
                                        echo $row['PRODUCTSSERVICES'];
                                        echo "</td></tr>";
                        }
                        echo "</table>";
                }
        ?> 

答案 2 :(得分:0)

echo "
<table><tr><th>Name</th>
<th>Location</th>
<th>Products/Services</th></tr>
";
while($row = mysql_fetch_array($qu))
{
    echo "<tr><td>";  
    echo $row['COMPANY'];
    echo "</td>";
    echo "<td>";
    echo $row['LOCATION'];
    echo "</td>";
    echo "<td>";
    echo $row['PRODUCTSSERVICES'];
    echo "</td></tr>";
}
echo "</table>";

回复你的评论,试试这个