gpt4 book ai didi

PHP 搜索只显示一个结果?

转载 作者:行者123 更新时间:2023-11-30 01:00:02 24 4
gpt4 key购买 nike

有人可以帮助我吗,我有一个 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>";
}
}
?>

通过搜索TV可以在www.healthcareservicesdirect.com看到搜索,应该会显示Sky & Virgin,但目前只显示Sky

最佳答案

我刚刚看了它,我看到它列出了维珍!它只是不像第一个条目那样出现在表中。它位于页面底部。要解决此问题,您必须将 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>";
}
?>

关于PHP 搜索只显示一个结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20222068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com