title: how to echo out search query results in new window?
body: <p>I'm trying to figure out how to echo search results into a new window.</p>
  
  <p>Basically a user can type in the search bar location, name etc and it will bring up 5 user results of how ever many users exist for that result. This is to limit space usage. Then a user can click view more results and is taken to another page where it carry's the query across and should echo out only those users matching the query in the search; i.e those users in 'london'.</p>
  
  <p>But at the moment all my users are displaying and i don't know why this is. can someone please show me where I'm going wrong. Thanks.</p>
  
  <p>Here's my search.php page limiting search results to 5:</p>
  
  
      
      
      
  
  <pre><code>&lt;?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 "&lt;div class=\"search-results\"&gt;";
  while($data_fetch=mysql_fetch_array($query_for_result))
  
  {
  
      echo "&lt;div class=\"text\"&gt;&lt;a href=\"profile.php?id={$data_fetch['user_id']}\" class=\"search\"&gt;";
      echo "&lt;div class=\"spacing\"&gt;&lt;img width=35px height= 30px src=\"data/photos/{$data_fetch['user_id']}/_default.jpg\" class=\"boxgridsearch\"/&gt; "; 
       echo substr($data_fetch[$db_tb_atr_name], 0,160);
      echo "&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;";
  
  }
  echo "&lt;div class=\"morebutton-search\"&gt;&lt;a href=\"search_results.php?to=%$query%\" target=\"_blank\" \"&gt;+ view more results&lt;/a&gt;&lt;/div&gt;";
  
  
  mysql_close();
  }
  
  ?&gt;
  </code></pre>
  
  <p>And Here's my more_search_results.php page to display all results matching query:</p>
  
  <pre><code>&lt;?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 "&lt;div class=\"search-results\"&gt;";
  while($data_fetch=mysql_fetch_array($query_for_result))
  
  {
  
      echo "&lt;div class=\"boxgrid caption\"&gt;&lt;a href=\"profile.php?id={$data_fetch['user_id']}\"&gt;&lt;img width=140px height=180px src=\"data/photos/{$data_fetch['user_id']}/_default.jpg\"&gt;&lt;div class=\"cover boxcaption\"&gt;"; ?&gt;
      &lt;h58&gt;&lt;? echo substr($data_fetch[$db_tb_atr_name], 0,160);?&gt;&lt;/a&gt;&lt;/h58&gt; 
      &lt;/div&gt;
      &lt;/div&gt;
  &lt;? } ?&gt;
  </code></pre>