Php 将搜索查询链接到新页面?

Php 将搜索查询链接到新页面?,php,mysql,search,Php,Mysql,Search,可能重复: 我有两个问题。我正在使用这个搜索查询脚本从我的数据库中提取结果,它的设置是基于位置、性别等搜索用户 结果列表位于下拉框中,为了节省空间,我将显示的结果数量限制为五个 我创建了一个链接,上面写着“查看更多结果”,因为我尝试的是让用户单击此链接并进入一个新页面,在该页面中列出了所有符合其原始搜索条件的结果。如果能做到这一点,我已经尝试了很多方法,但没有任何运气 此外,我还试图排除5个配置文件;999998、999997、99966995、999994、999993通过将此行添加到查询:

可能重复:

我有两个问题。我正在使用这个搜索查询脚本从我的数据库中提取结果,它的设置是基于位置、性别等搜索用户

结果列表位于下拉框中,为了节省空间,我将显示的结果数量限制为五个

我创建了一个链接,上面写着“查看更多结果”,因为我尝试的是让用户单击此链接并进入一个新页面,在该页面中列出了所有符合其原始搜索条件的结果。如果能做到这一点,我已经尝试了很多方法,但没有任何运气

此外,我还试图排除5个配置文件;999998、999997、99966995、999994、999993通过将此行添加到查询:

和ptb_profiles.user_id!='99999'

但当我这样做时,整个查询会产生一个错误:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/PTB1/includes/mod_sidebar/search.php on line 31
有人能告诉我怎么做吗。多谢各位

<form method="get" action="">
<input type="text" name="query" class="searchbox" placeholder="Search Name/Location" style="width:120px;"/>
<input type="image" src="../PTB1/assets/img/icons/search.png" height="19" width="20" class="searchbutton" name="submit" value="Start Search" />
</form>

<?php
//PHP CODE STARTS HERE

if(isset($_GET['submit'])){

// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";
$db_password="";
$db_name="database";
$db_tb_atr_name="display_name";

//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen

mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");

$query=mysql_real_escape_string($_GET['query']);


$query_for_result=mysql_query("SELECT *
                        FROM ptb_stats
                        WHERE display_name like '%".$query."%' OR location LIKE '%".$query."%' OR gender LIKE '%".$query."%' OR nationality LIKE '%".$query."%' OR age LIKE '%".$query."%' OR postcode LIKE '%".$query."%' LIMIT 5");
echo "<div class=\"search-results\">";
while($data_fetch=mysql_fetch_array($query_for_result))
{

    echo "<div class=\"text\"><a href=\"profile.php?id={$data_fetch['user_id']}\" class=\"search\">";
    echo "<div class=\"spacing\"><img width=35px height= 30px src=\"data/photos/{$data_fetch['user_id']}/_default.jpg\" class=\"boxgridsearch\"/> "; 
     echo substr($data_fetch[$db_tb_atr_name], 0,160);
    echo "</a></div></div>";

}
echo "<div class=\"morebutton-search\"><a href=\"echo '%".$query."%'\">+ view more results</a></div>";

mysql_close();
}

?>


这应该是mysql语句的一个错误。您正在从
ptb_stats
中选择数据,但您正在检查
ptb_配置文件中的值

假设两个表都以
user\u id
为主,则使用
ptb\u stats.user\u id
而不是
ptb\u profiles.user\u id
并执行以下更改

$query_for_result=mysql_query("SELECT *
                        FROM ptb_stats
                        WHERE (display_name like '%".$query."%' OR location LIKE '%".$query."%' OR gender LIKE '%".$query."%' OR nationality LIKE '%".$query."%' OR age LIKE '%".$query."%' OR postcode LIKE '%".$query."%') AND ptb_stats.user_id!='99999' LIMIT 5");
确保使用括号作为我的代码,因为有两个不同的条件需要检查

  • 查找查询的匹配数据
  • 检查这些数据并排除配置文件id
如果您没有像上面那样使用括号,您的代码将给您一个错误


希望这对您有所帮助。

。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果您选择PDO,。根据无数其他问题和您的确切错误消息:您的查询失败了,您假设它总是成功的,并且没有进行任何错误检查。添加它,mysql会告诉你为什么会有问题。@John你是说当你排除配置文件时会出现错误吗。是吗?@Jocelyn-我的问题和那个问题完全不同。所以根本不可能重复。@John yes和ptb_profiles.user_id!='99993'是导致错误消息的原因,但我不知道为什么。有什么建议吗