我有两个问题。我正在使用这个搜索查询脚本从我的数据库中提取结果,它设置为根据位置、性别等搜索用户。
下拉框中的结果列表为了节省空间,我将显示的结果数量限制为五个。
我创建了一个链接,上面写着查看更多结果,因为我要做的是使用户能够单击此链接并被带到一个新页面,其中列出了其原始搜索条件的所有结果。这可以做到吗,我已经尝试了很多方法,但没有任何运气。
我也试图排除 5 个配置文件;99999, 99998, 99997, 99996, 99995, 99994, 99993 通过将此行添加到查询中:
AND 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();
}
?>