title: Mysql query to get all different messages for same user
body: <p>This a simple chat table</p>
  
  <pre><code>id| fromUserId| toUserId| message
  </code></pre>
  
  <p>Let's take dummy data John (45), Jane(46) and Mary(47). Say John chats with both Jane and Mary at the same time.</p>
  
  <p>John (45) started the conversation with Jane (46) so data looks like this:</p>
  
  <pre><code>id| fromUserId| toUserId| message
  1 | 45        | 46      | wassup?
  </code></pre>
  
  <p>In the second context, Mary (47) started conversation with John (45)</p>
  
  <pre><code>id| fromUserId| toUserId| message
  2 | 47        | 45      | wassup?
  </code></pre>
  
  <p>How can I display the two different conversations to John? I'm using this query but it does not work:</p>
  
  <pre><code>    &lt;?php
          $chatmsgQ="SELECT * FROM ve_chat c 
         WHERE c.isActive='1' AND c.fromUserId='$loginid_session' 
         OR c.toUserId='$loginid_session'";
      $chatmsgresult=  mysqli_query($db,$chatmsgQ);?&gt;
  </code></pre>
  
  <p><strong>EDIT WITH USAGE</strong></p>
  
  <pre><code>      &lt;ul class="dropdown-menu" style="overflow-x: hidden;"&gt;
        &lt;?php
        $chatmsgQ="SELECT * FROM ve_chat c WHERE c.isActive='1' AND (c.fromUserId='$loginid_session' OR c.toUserId='$loginid_session') GROUP BY (c.fromUserId='$loginid_session' OR c.toUserId='$loginid_session')";
        $chatresultse=  mysqli_query($db,$chatmsgQ);
        while($chatboxes=  mysqli_fetch_array($chatresultse)){;?&gt;
        &lt;li  style="font-size: small; "&gt;
        &lt;a style='width: 100% !important;' href='' data-toggle='modal' data-target='#chatModal'&gt;
        Chat  with &lt;?=$chatresultuseres['ProfileName'];?&gt; | &lt;?=$rowChat[0];?&gt; Msg (s)
                  &lt;/a&gt;
                   &lt;/li&gt;
              &lt;?php } ;?&gt;
      &lt;/ul&gt;
  </code></pre>