0
我想弄清楚如何將搜索結果回顯到新窗口中。如何在新窗口中回顯搜索查詢結果?
基本上,用戶可以輸入搜索欄的位置,名稱等,它會帶來5個用戶的結果,如果有多少用戶存在的結果。這是爲了限制空間使用量。然後,用戶可以單擊查看更多結果,並將其帶到另一個頁面,在該頁面中進行查詢,並且只應回覆那些與搜索中的查詢匹配的用戶;即「倫敦」中的那些用戶。
但目前我的所有用戶都在顯示,我不知道這是爲什麼。有人可以告訴我哪裏出錯了。謝謝。
這裏是我的限制搜索結果的search.php頁面5:
<?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="";
$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 age LIKE '%".$query."%' OR nationality LIKE '%".$query."%' OR ethnicity LIKE '%".$query."%' OR hobbies LIKE '%".$query."%' OR local_station 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=\"search_results.php?to=%$query%\" target=\"_blank\" \">+ view more results</a></div>";
mysql_close();
}
?>
,這裏是我的more_search_results.php頁面來顯示所有的結果匹配查詢:
<?php
$db_host="localhost";
$db_username="root";
$db_password="";
$db_name="";
$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 age LIKE '%".$query."%' OR nationality LIKE '%".$query."%' OR ethnicity LIKE '%".$query."%' OR hobbies LIKE '%".$query."%' OR local_station LIKE '%".$query."%'");
echo "<div class=\"search-results\">";
while($data_fetch=mysql_fetch_array($query_for_result))
{
echo "<div class=\"boxgrid caption\"><a href=\"profile.php?id={$data_fetch['user_id']}\"><img width=140px height=180px src=\"data/photos/{$data_fetch['user_id']}/_default.jpg\"><div class=\"cover boxcaption\">"; ?>
<h58><? echo substr($data_fetch[$db_tb_atr_name], 0,160);?></a></h58>
</div>
</div>
<? } ?>
不應該在新創建的代碼中使用MySQL,學習不折舊的備選方案,這些備選方案是MySQLI或PDO。 –