title: Getting multiple rows of the same thing from database
body: <p>I'm having some issues with this mysql database i got from school. I'm getting duplicate rows with the same name but different quantities. I would suppose that this is because 'inventory' contains columns with the same name as in 'sets'. But i really can't get it to work. Thank you in advance for all your help. </p>
  
  <p>Database schematic (in Swedish, but the titles are in English.):
  <a href="http://weber.itn.liu.se/~stegu76/TNMK30-2016/legodatabasen.pdf" rel="nofollow noreferrer">http://weber.itn.liu.se/~stegu76/TNMK30-2016/legodatabasen.pdf</a></p>
  
  <p><a href="https://i.stack.imgur.com/wcNJo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wcNJo.png" alt="A screenshot from the results on the webpage"></a>
  <strong>I'm very new to this so any tips would be appreciated.</strong> </p>
  
  <pre><code>$setidquery = "SELECT inventory.Quantity, inventory.ItemID, inventory.ColorID, colors.Colorname, parts.Partname, sets.SetID, sets.Year, inventory.ItemtypeID FROM `inventory`, `parts`, `colors`, `sets` WHERE sets.SetID='$_COOKIE[setid]' AND inventory.ItemID=parts.PartID AND inventory.ColorID=colors.ColorID ORDER BY Partname ASC LIMIT 1000";
  
    echo "&lt;table class=\"table\"&gt;";
    echo "&lt;tr&gt;&lt;th&gt;Quantity:&lt;/th&gt;&lt;th&gt;Year:&lt;/th&gt;&lt;th&gt;Partname:&lt;/th&gt;&lt;th&gt;ItemID:&lt;/th&gt;&lt;th&gt;SetID&lt;/th&gt;&lt;th&gt;Image:&lt;/th&gt;&lt;/tr&gt;";
  
    while($row = mysqli_fetch_array($result)){
        $prefix = "http://www.itn.liu.se/~stegu76/img.bricklink.com/";
  
        $Year = $row['Year'];
        $Quantity = $row['Quantity'];
        $ItemID = $row['ItemID'];
        $ColorID = $row['ColorID'];
        $Partname = $row['Partname'];
        $SetID = $row['SetID'];
        $ItemtypeID = $row['ItemtypeID'];
  
        $imagesearch = mysqli_query($conn, "SELECT * FROM `images` WHERE ItemTypeID = '$ItemtypeID' AND ItemID = '$ItemID' AND ColorID = '$ColorID' ");
  
        $imageinfo = mysqli_fetch_array($imagesearch);
  
        if($imageinfo['has_jpg']) {
          $filename = "$ItemtypeID/$ColorID/$ItemID.jpg";
        } else if($imageinfo['has_gif']) {
          $filename = "$ItemtypeID/$ColorID/$ItemID.gif";
        } else {
          $filename = "noimage_small.png";
        }
  
        echo "&lt;tr&gt;
                &lt;td&gt;$Year&lt;/td&gt;
                &lt;td&gt;$Quantity&lt;/td&gt;
                &lt;td&gt;$Partname&lt;/td&gt;
                &lt;td&gt;$ItemID&lt;/td&gt;
                &lt;td&gt;$SetID&lt;/td&gt;
                &lt;td&gt;&lt;img src=\"$prefix$filename\" alt=\"Part $ItemID\"/&gt;&lt;/td&gt;
              &lt;/tr&gt;";
    }
        echo "&lt;/table&gt;";
  </code></pre>
  
  <p>Here is the query formatted for readability:</p>
  
  <pre><code>SELECT inventory.Quantity, 
         inventory.ItemID, 
         inventory.ColorID, 
         colors.Colorname, 
         parts.Partname, 
         sets.SetID, sets.Year, 
         inventory.ItemtypeID
    FROM `inventory`, `parts`, `colors`, `sets`
   WHERE sets.SetID='$_COOKIE[setid]' 
    AND inventory.ItemID=parts.PartID
    AND inventory.ColorID=colors.ColorID
  ORDER BY Partname ASC LIMIT 1000;
  </code></pre>