-1
我試圖用我的搜索腳本做2件事。將語句添加到mysql並將搜索查詢添加到新頁面?
一個我想知道我可以如何添加一個if語句來說,如果沒有找到結果回聲「沒有結果」。
其次,此刻我將結果限制爲5,但我希望用戶能夠點擊查看更多結果,如果他們一直在尋找的「倫敦」用戶,那麼一旦他們點擊查看所有結果,這將打開在新窗口中顯示搜索結果並顯示在新窗口中?
任何人都可以請幫助我,一直在這工作了一段時間,我仍然在學習PHP和MySQL。
<?php
//PHP CODE STARTS HERE
if(isset($_GET['submit'])){
// Change the fields below as per the requirements
$db_host="###";
$db_username="###";
$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 hobbies LIKE '%".$query."%' OR nationality LIKE '%".$query."%' OR gender 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_escorts.php?to=echo '%".$query."%'\" target=\"_blank\" \">+ view more results</a></div>";
mysql_close();
}
?>