title: limit mysql query to 1 result?
body: <p>I have search script running from mysql query. It pulls the matching users from the database if their display_name or location is like the query. When I perform a search for a users display name I get just one result for each user like so:</p>
  
  <p>search 'Tom' = 2 results for tom = 1.tom davies and 2.tom smith.</p>
  
  <p>for whatever reason if I search location i.e. manchester it duplicates the results for each user like:</p>
  
  <p>Tom davies
  Tom davies
  Tom davies
  Tom davies 
  Tom smith
  Tom smith 
  Tom smith
  tom smith</p>
  
  <p>Can someone please explain how I can stop it from doing this. I only want it to bring up one result for each of the users that match the search query rather than display the same user several times. I'm sure it's something to do with the select all from ptb_users and ptb_profiles, but I need the 'account type' and 'account_status' to be included which are in ptb_users.</p>
  
  <p>Thanks </p>
  
  <p>
      
      
      </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="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_users, ptb_profiles
                          WHERE ptb_users.account_type = \"User\" AND ptb_users.account_status = \"Active\" AND ptb_profiles.user_id = ptb_users.id AND display_name like '%".$query."%' 
          OR location LIKE '%".$query."%' OR age LIKE '%".$query."%'");
  echo "&lt;div class=\"results\"&gt;";
  while($data_fetch=mysql_fetch_array($query_for_result))
  {
      echo "&lt;div class=\"spacing\"&gt;&lt;a href=\"profile.php?id={$data_fetch['user_id']}\"&gt;";
      echo substr($data_fetch[$db_tb_atr_name], 0,160);
      echo "&lt;/a&gt;&lt;/div&gt;";
  
  }
  
  
  mysql_close();
  }
  
  ?&gt;
  </code></pre>