Ik hen een tabel1 deze kan ik ophalen en tonen op het scherm. Ik heb vervolgend ook een andere tabe2 waarin ik het id van tabel1 heb opgenomen.
ik wil nu de gegevens uit tabel1 tonen met het aantal waarvan het id voorkomt in tabel2.
dus zo
ditiseennaamintabel1 (2)
De 2 is omdat de id van ditiseennaamintabel1 2 keer voorkomt in tabel2.
Dit is wat ik heb. (let niet op de inline css... dat ga ik opruimen)
<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, naam FROM producten";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if( $i >= 8 ){ $i = 0; echo '<div style="clear:both;margin-bottom:10px;"></div>'; }
echo '
<a style="color:#000000;text-decoration:none" href="icondetail.php?id='.$row["id"]. '">
<div align="center" style="width:150px;height:100px;background-color:#f4f4f4;float:left;margin-left:10px;padding-top:20px;">
'.$num_rows.'
<img style="width:75px;" src="producten/' . $row["naam"]. '.svg" /><br>
<small>' . $row["id"]. '' . $row["naam"]. '' . $row["omschrijving"]. '</small>
</div></a>';
$i++;
}
} else {
echo "0 results";
}
$conn->close();
?>