I have this code:
if ($object_id != $cur_object_id) {
?>
<div class="workbench_object_wrap">
<p class="text_center"><u><?php echo $object_name; ?></u></p>
<div class="workbench_object_img">
<img style="max-width: 100px; max-height:100px;" src="<?php echo $src. "2.png";?>">
</div>
<div class="workbench_object_info_wrap">
<div class="workbench_object_info">
<?php
}
?>
<p><?php echo $material_name; ?><i style="float:right;"><?php echo $material_amount; ?></i></p>
<?php
if ($object_id != $cur_object_id) {
?>
<div class="craft">
<button id= "craft-<?php echo $object_id; ?>" class="craft" onclick="craft(this);">Craft</button>
</div>
</div>
</div>
</div>
<?php
$cur_object_id = $object_id;
}
Which is inside a while loop that iterates over everything returned by the database query.
So I want the $object_name to appear once for each object. Each object has some names: $material_name. And after all those material names has been printed, I want the div to close itself and print craft only once for every object.
This image represents the output I get from the database. As you can see, the same object_id appears twice, and therefore I have made the $cur_object_id since I only want the object name once (Royal Chair) however I want both of the material names (Stone and Birch Log) to be displayed BEFORE the last div is closed.

This is probably done with some boolean values checking if the object_id is still the same or some logic like that but I just can't figure a way to accomplish this. Thanks in advance!