I'm trying to do 2 things with my search script.
One i want to know how i could add a if statement to say if not results found echo "no results".
And secondly at the moment i limit results to 5, but i want the user to be able to click view more results and if they have been searching for users in 'London' then once they click view all results this will open in a new window and have all the results for their search displayed in the new window?
Can anyone please help me, have been working on this for some time and am still learning php and 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();
}
?>