PHP Why does my foreach loop only give 1 result? : <p>Why does my foreach only show 1 result and why not both results, since it clearly shows in my database there are 2 results with Com_Id 1 but still it only gives me 1 result. This is how my Database looks like <a href="https://i.stack.imgur.com/xuXjt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xuXjt.jpg" alt="database"></a></p>

<p>this are the results that I get</p>

<p><a href="https://i.stack.imgur.com/0U3es.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0U3es.jpg" alt="enter image description here"></a></p>

<pre><code>$id = $_GET['view'];
</code></pre>

<p>Mycode:</p>

<pre><code>&lt;?php
    $sql = "SELECT * FROM IA_Monitor WHERE Com_ID = :id";
    $query = $conn-&gt;prepare($sql);
    $query-&gt;execute(array(':id' =&gt; $id));
    while($row = $query-&gt;fetch(PDO::FETCH_ASSOC)){
        $mon_comid = $row['Com_ID'];
        $mon_barcode[0] = $row['Barcode'];
        $mon_merk = $row['Merk'];
        $mon_type = $row['Type'];
        $mon_inch = $row['Inch'];
        $mon_a_dat = $row['Aanschaf_dat'];
        $mon_a_prijs = $row['Aanschaf_waarde']; 
    }
$monnewDate = date("d-m-Y", strtotime($mon_a_dat));
if($id==$mon_comid){
foreach($mon_barcode as $key =&gt; $value){
    ?&gt;
    &lt;title&gt;&lt;?php echo $value; ?&gt;&lt;/title&gt;
    &lt;table&gt;
        &lt;tr&gt;&lt;td&gt;Monitorbarcode: &lt;/td&gt;&lt;td&gt;&lt;?php echo $value;?&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Merk: &lt;/td&gt;&lt;td&gt;&lt;?php echo $mon_merk;?&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Type: &lt;/td&gt;&lt;td&gt;&lt;?php echo $mon_type;?&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Inch: &lt;/td&gt;&lt;td&gt;&lt;?php echo $mon_inch;?&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Aanschaf datum: &lt;/td&gt;&lt;td&gt;&lt;?php echo $monnewDate;?&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Aanschaf waarde: &lt;/td&gt;&lt;td&gt;&lt;?php echo "&amp;euro;".number_format((float)$mon_a_prijs, 2, '.', '')."";?&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;/table&gt;
    &lt;?php
}}else{
    echo "&lt;i&gt;Geen monitoren gevonden&lt;/i&gt;";
}
?&gt;
</code></pre>

<p>Does anyone have any idea why it doesnt work and could you maybe help me understand and help me with fixing this?</p>
