I’m trying to link two tables in the same database using a third.
The first table is product and has the productcode. The second table is shop and has the shopcode.
The third table has the shopcode and corresponding productcode.
However not all products are sold and now it just deletes those products at the results.
This shrinks the list from 1600 to 753, however I want to see the list of products and the shops are a secondary issue.
So instead of deleting the entire row i’d like the table to just say that there is no shop selling it by leaving the area grey or stating NULL.
I’ve used:
SELECT * FROM product, sells
WHERE product.productcode = sells.shopcode
ORDER BY product.productcode.
I’ve tried to find it using google and a few of my friends but I can’t seem to find the answer.
Thanks all of you,
Jell0zz
EDIT: after Tamago’s help i’ve got everything in the right table however on firefox atleast, another problem is that when there is no value instead of leaving the borders of the table it leaves an empty space, this makes it look like there are parts missing. Also, in the first colomn i put the productID, however it seems to only show the productID if it is in the sells as well, otherwise it leaves an empty space as well.
The code:
$sql = 'SELECT * FROM bier LEFT JOIN schenkt ON bier.biercode = schenkt.biercode LEFT JOIN kroeg ON schenkt.kroegcode = kroeg.kroegcode'; $resultaat = $db->query($sql); echo '<table border = 0>'; echo "<tr> <td style = 'width:100%;'>"; echo '<table border = 1>'; foreach($resultaat as $row) { echo '<tr>'; $nummer = $row['bier.biercode']; echo '<td>'.$row['bier.biercode'].'</td>'; echo '<td>'.$row['naam'].'</td>'; echo '<td>'.$row['type'].'</td>'; echo '<td>'.$row['stijl'].'</td>'; echo '<td>'.$row['alcohol'].'</td>'; echo '<td>'.$row['kroegnaam'].'</td>'; echo '<td>'.$row['adres'].'</td>'; echo '<td>'.$row['plaats'].'</td>';
It might be worth noting that t1=bier (or beer in english) t2=schenkt (or sells) and t3=kroeg (or bar)
Disclaimer, I’m not an alcoholic but I think my teacher might be 😉
1 Answer