title: SELECT data from multiple tables PHP/Mysql
body: <p>I'm trying to get data from multiple tables to build a notifications feed. </p>
  
  <p>I have 3 tables: <strong>users</strong>, <strong>user_notification</strong> and <strong>user_comments</strong></p>
  
  <p>When I click on the icon to check the notifications, I want to display as a dropdown only the new ones, so in the <strong>user_notification</strong> table I have the rows <strong>"status"</strong>, <strong>id_from</strong> and <strong>id_owner</strong> which can be <strong>"new"</strong> or <strong>"old"</strong>, that way I know what to retrieve, but then my problem comes when I need to get from those notifications, the info about who was it and be able to display the for instance, the profile picture, username, comment_id, etc.</p>
  
  <p>This is the HTML I am trying to get:</p>
  
  <pre><code>while ($row_notification = $result_load_notifications-&gt;fetch_assoc()) {
  
              echo '&lt;li class="dropdown-item"&gt;
                      &lt;img src="'.$row_notification["avatar"].'" class="avatar-feed" alt="'.$row_notification["name"].'" /&gt;&lt;p&gt;&lt;strong&gt;'.$row_notification["name"].'&lt;/strong&gt; new &lt;a href="https://sample.com/user/'.$_SESSION['alias'].'/#comment-'.$row_notification["id_comment"].'"&gt;comment&lt;/a&gt; notification.&lt;br&gt;
                      &lt;time class="date-post" datetime="'.$row_notification["date"].'"&gt;&lt;/time&gt;&lt;/p&gt;
                      &lt;/li&gt;';
              echo '&lt;li class="dropdown-divider"&gt;&lt;/li&gt;';
  
          }
  </code></pre>
  
  <p>And this is the PHP/Mysqli I thought could work but didn't:</p>
  
  <pre><code>SELECT
      *
  FROM
      user_notification n,
      users u,
      user_comments c
  WHERE
      n.status='new'
      AND
      n.id_owner=$session_id
      AND
      u.id_user=n.id_from
      AND
      c.id_owner=n.id_owner
  </code></pre>
  
  <p>In PHP:</p>
  
  <pre><code>$load_notifications = mysqli_query($conn, "SELECT * user_notification n, users u, user_comments c WHERE n.status='new' AND n.id_owner=$session_id AND u.id_user=n.id_from AND c.id_owner=n.id_owner");
  </code></pre>
  
  <p>That code just does not work, am I doing something wrong? (I am not an expert) am I missing a relation between tables?</p>
  
  <p>Any tip would be appreciate it,
  Thanks.</p>