title: Join SQL query that has single id/row in 1 table, but links to multiple rows(same id) in another table?
body: <p>First sorry for the long question title. </p>
  
  <p>My question/situation is as such.</p>
  
  <p>1.) I have 2 tables in mysql</p>
  
  <p>2.) In first table, each listing has a unique id(each listing is in 1 row)</p>
  
  <p>3.) In the second table it has the name/tags for images linked to the listing id,from the first table</p>
  
  <p>4.) Each listing can have multiple images(multiple row in the second table).</p>
  
  <p>What i am trying to do is to pull all the listings from table 1 and then use the listing.id from table one to pull all the rows of images from table 2 that are linked to the listing.id.
  I am confused at the moment because there are multiple rows that has the same listing.id from table 2. ANd i tried query to display* but it only echo the last image(row) from table 2. </p>
  
  <p>It doesnt seem to work when i join the 2 tables. And i am not sure if i query it twice then push array together. </p>
  
  <p>Thanks for your time</p>
  
  <pre><code> $result=mysqli_query($con,"SELECT * FROM Listing JOIN listingpic ON 
      (Listing.id = listingpic.listingid)
  
   WHERE date &gt;= curdate() - INTERVAL DAYOFWEEK(curdate())+300 DAY GROUP BY Listing.id ORDER BY Listing.id DESC") or die( mysqli_error($con));
  
  while ($row = mysqli_fetch_assoc($result))
          {
    $output[] = $row;
          }
          if (!empty($output)){
  
          echo json_encode( $output );}
          else{
  
              echo json_encode( [] );
          }
  </code></pre>