I have products, All of these products have for example. An id, name and price. All of these products are connected in the database like this:
Since I don't have 10 reputation... Here is a link to a picture http://puu.sh/oS95c/b7b5b17427.png
What I want to achieve is to have products that are connected to another product show up on the screen using inner join. However instead of getting the connected items back I get back every item of the right column even if they are not connected.
Here is a link to get a better view of the database: http://puu.sh/oSBF2/1af1ce3751.png
$sql = "SELECT AFBEELDING_KLEIN, PRODUCTNAAM, PRIJS
FROM PRODUCT
inner JOIN PRODUCT_GERELATEERD_PRODUCT
ON PRODUCT.PRODUCTNUMMER=PRODUCT_GERELATEERD_PRODUCT.PRODUCTNUMMER_GERELATEERD_PRODUCT";
$result = sqlsrv_query($db, $sql);
$data = sqlsrv_fetch_array($result);
while($data = sqlsrv_fetch_array($result)) {
$big_picture = '<img src="../' . $data["AFBEELDING_KLEIN"] . '"' . 'alt="product">';
$link = '<a href="../productpaginas/' . $data["PRODUCTNAAM"] . '.php"<p> ' . $data["PRODUCTNAAM"] . '</p></a>';
$price = '<h2> €' . $data["PRIJS"] . '</h2>';
echo '<div class="product">';
echo $big_picture;
echo $link;
echo $price;
echo '</div>';
}