title: how select with from mutiple table
body: <pre><code>id  friend1 friend2
  1   obi      ezenwa
  2   obi      obinna
  3   obi      ezenwa
  </code></pre>
  
  <p>this is how i select the list of friends from the table above</p>
  
  <pre><code>&lt;?php
  
  require("config.inc.php");
  
  if (!empty($_POST)) {
  $query = "SELECT users.* FROM users WHERE users.username IN 
  (SELECT friend2 FROM friends where friend1=:username
  UNION
  SELECT
  friend1 FROM friends where friend2=:username)";
  
      $query_params = array(
          ':username' =&gt; $_POST['username']
      );
  
  
  try {
      $stmt   = $db-&gt;prepare($query);
      $result = $stmt-&gt;execute($query_params);
  }
  catch (PDOException $ex) {
      $response["success"] = 0;
      $response["message"] = "Database Error!";
      die(json_encode($response));
  }
  $rows = $stmt-&gt;fetchAll();
  
  
  if ($rows) {
      $response["success"] = 1;
      $response["message"] = "Post Available!";
      $response["posts"]   = array();
  
      foreach ($rows as $row) {
          $post             = array();
  
          $post["TAG_NAME"]    = $row["username"];
  
          array_push($response["posts"], $post);
      }
  
      echo json_encode($response);
  
  
  } else {
      $response["success"] = 0;
      $response["message"] = "No Post Available!";
      die(json_encode($response));
  }
  
  } else {
  ?&gt;
          &lt;h1&gt;Login&lt;/h1&gt; 
          &lt;form action="selectfriends.php" method="post"&gt; 
              Username:&lt;br /&gt; 
              &lt;input type="text" name="username" placeholder="username" /&gt; 
              &lt;br /&gt;&lt;br /&gt; 
  
              &lt;input type="submit" value="Login" /&gt; 
          &lt;/form&gt; 
          &lt;a href="register.php"&gt;Register&lt;/a&gt;
      &lt;?php
  }
  
  ?&gt; 
  </code></pre>
  
  <p>it works well i also have a table like this one below called chatt. where messages of users are saved.</p>
  
  <pre><code>                              Chatt
        fromm     too       message           time
          obi2    ezenwa  this is me yes  2015-02-08 23:47:31
          obi     ezenwa  ok i can see    2015-02-08 23:47:31
          obi     ezenwa  seems good      2015-02-12 17:44:10
          ezenwa  obi     i agree         2015-02-12 17:49:16
          obi     ezenwa  j man           2015-02-13 14:42:16
          obi     ezenwa  j man           2015-02-13 14:43:28
          obi2    ezenwa  this is cool    2015-02-13 14:58:28
  </code></pre>
  
  <p>i would like to display the last message between the username that has been enter and all his friends which contained in $row["username"] ...i just want the users list of friends and the last message between them just like blackberry messenger and WhatsApp ....</p>