I'm trying to display some data on a div with 3 fields by getting only the unique values from the table. The query used is working fine in pgAdmin3, but when trying to display it on the page, multiple divs are getting displayed based on an data scanned in the previous page.
Since it is an array, I'm using the foreach to display and that is the reason multiple divs are getting generated, and I don't know how to display data from an array without using loop.
Getting data scanned in the previous page
$strings = explode(PHP_EOL,trim($_SESSION['grid']));
Displaying data in the divs using foreach based on the number barcodes scanned in the previous page
foreach ($strings as $d){
$sql = "select distinct size from items where main_group IN(select distinct
main_group from items where addl_item_code_barcode IN ('$d')) ORDER BY
size";
$result = pg_query($db, $sql);
$res = pg_fetch_assoc($result);
?>
<div class="col-sm show-hide">
<input type="text" value="<?php echo $res['size']; ?> " readonly
style="background-color: #F5F5F5;" class="form-control"><br>
<input class="form-control" type="text" name="n2" id="n2"/><br>
<select class="form-control">
<option>25%</option>
<option>50%</option>
<option>100%</option>
</select><br>
</div>
<?php }?>
I scanned 2 barcodes in the previous page which has the same value '36' in the field 'size'. Since 2 data was scanned, the loop ran twice and got displayed twice. How do I display it only once.
Here's how the page looks like now. https://ibb.co/qDh425j