title: Trouble with SQL query and php
body: <p>I'm at the stage where I'm just starting to understand PHP and MySQL but I am stuck. I have been studying a tutorial from developphp.com in which Shawn's WI is building a message system</p>
  
  <pre><code>https://www.youtube.com/playlist?list=PLgsYR-L3Uwbps9E-xIQPajQOiZVbOo6lr
  </code></pre>
  
  <p>I am trying to redesign the tutorial so it fits my needs. i have built a mail page called pm_inbox.php which works fine, it gives me mail that has been sent to me in a DESC order. </p>
  
  <p>pm_inbox.php</p>
  
  <pre><code>$sql = "SELECT pm.*, u.avatar, u.country 
  FROM pm AS pm
  LEFT JOIN users AS u ON u.username = pm.sender
  WHERE (pm.receiver='$u' AND pm.parent='x' AND pm.rdelete='0')
  OR (pm.sender='$u' AND pm.sdelete='0' AND pm.parent='x' AND pm.hasreplies='1')
  ORDER BY senttime DESC";
  $query = mysqli_query($db_conx, $sql);
  $statusnumrows = mysqli_num_rows($query);
  // Gather data about parent pm's
  if($statusnumrows &gt; 0){
      while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
          $pmid = $row["id"];
          //div naming
          $pmid2 = 'pm_'.$pmid;
          $wrap1 = 'pm_message_wrap_'.$pmid;
          //button naming
          $btid2 = 'bt_'.$pmid;
          //textarea naming
          $rt = 'replytext_'.$pmid;
          //button naming
          $rb = 'replyBtn_'.$pmid;
          $receiver = $row["receiver"];
          $sender = $row["sender"];
          $subject = $row["subject"];
          $message = $row["message"];
          $time = $row["senttime"];
          $rread = $row["rread"];
          $sread = $row["sread"];
          $avatar = $row["avatar"];
          $country = $row["country"];
  
          // Start to build our list of parent pm's
          $mail .= '&lt;div id="'.$wrap1.'" class="pm_message_wrap"&gt;';
          $mail .= '&lt;table id="inboxMailMessages" width="100%" align="center" cellpadding="2"&gt;
    &lt;tr&gt;
      &lt;td width="6%"&gt;&lt;input name="toggleAll" id="toggleAll" type="checkbox"/&gt;&lt;/td&gt;
      &lt;td width="19%"&gt;&lt;a href="user.php?u='.$sender.'" title="'.$sender.'"&gt;&lt;img src="user/'.$sender.'/'.$avatar.'"width=100" height="100" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;td width="75%"&gt;
      &lt;div class="inboxmailRollover"&gt;
      &lt;p class="mailboxp"&gt;Subject: ' .$subject. '&lt;br&gt;&lt;/p&gt;
      &lt;p class="mailboxp"&gt;&lt;a href="user.php?u=' . $sender . '"&gt;From:'.$sender. '&lt;/a&gt;&lt;br&gt;&lt;/p&gt;
      &lt;p class="mailboxp"&gt;&lt;a href="inboxMain.php?u=' . $u . '"&gt;' .$country. '&lt;/a&gt;&lt;br&gt;&lt;/p&gt;
      &lt;p class="mailboxp"&gt;' .$message. '&lt;/p&gt;
      &lt;/div&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;';
          $mail .= '&lt;hr&gt;';
          $mail .= '&lt;/div&gt;';
  </code></pre>
  
  <p>what i am trying to do is when someone clicks the country link on pm_inbox.php it will take them through to another page called inboxMain.php in which it will show the persons details in a container who has sent the mail as in the sender, the subject and the country.</p>
  
  <p>i have 4 mail on pm_inbox.php that people have sent me. when i push on the country link it takes me through to inboxMain.php but instead of showing me just the persons details that has sent me the mail it shows all 4 peoples details in 4 separate containers. i know it is a sql query problem on inboxMain.php but cant work it out. i wonder if someone can help me please.</p>
  
  <p>inboxMain.php</p>
  
  <pre><code>$sql = "SELECT pm., u.avatar, u.country 
  FROM pm AS pm
  LEFT JOIN users AS u ON u.username = pm.sender
  WHERE pm.id='$pmid' AND pm.sender='$u' AND pm.sdelete='0' AND pm.parent='x'";
  $query = mysqli_query($db_conx, $sql);
  $statusnumrows = mysqli_num_rows($query);
  // Gather data about parent pm's
  if($statusnumrows &gt; 0){
      while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
          $pmid = $row["id"];
          //div naming
          $pmid2 = 'pm_'.$pmid;
          $wrap2 = 'reply_profile_wrap'.$pmid;
          //button naming
          $btid2 = 'bt_'.$pmid;
          //textarea naming
          $rt = 'replytext_'.$pmid;
          //button naming
          $rb = 'replyBtn_'.$pmid;
          $receiver = $row["receiver"];
          $sender = $row["sender"];
          $subject = $row["subject"];
          $message = $row["message"];
          $time = $row["senttime"];
          $rread = $row["rread"];
          $sread = $row["sread"];
          $avatar = $row["avatar"];
          $country = $row["country"];
  
          // Start to build our list of parent pm's
          $reply_profile .= '&lt;div id="'.$wrap2.'" class="reply_profile_wrap"&gt;';
          $reply_profile .= '&lt;table id="replyProfile" width="100%" border="0"&gt;
    &lt;tr&gt;
      &lt;td width="19%"&gt;&lt;a href="user.php?u='.$sender.'" title="'.$sender.'"&gt;&lt;img src="user/'.$sender.'/'.$avatar.'"width=75" height="75" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;    
      &lt;p class="replyProfilep"&gt;Subject: ' .$subject. '&lt;br&gt;&lt;/p&gt;
      &lt;p class="replyProfilep"&gt;&lt;a href="user.php?u=' . $sender . '"&gt;From:'.$sender. '&lt;/a&gt;&lt;br&gt;&lt;/p&gt;
      &lt;p class="replyProfilep"&gt;Country: ' .$country. '&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;';
  
          $reply_profile .= '&lt;/div&gt;';
  </code></pre>