idk if it’s possible, but I’m going to ask anyway.
I have a MYSQL database with a column called encounter, mode & encounter_id.
example: if the encounter_id value = 4, the encounter value = "Crota" (exists more than once) & the mode value is both "Normal" & "Master", is it possible to show "Crota" only once, but show both "Normal" & "Master" in an echo?
Query:
$ce = $database->pdo->query("SELECT * FROM `raid_list` WHERE `raid_id` = 13 ORDER BY `encounter_id` ASC")->fetchAll(PDO::FETCH_ASSOC);
PHP:
<?php foreach($ce as $data) {
echo '<div class="encounter">';
echo '<p>' . $data['encounter'] . '</p>';
echo '<p>(' . $data['mode'][0] . ')</p>';
echo '</div>';
} ?>
If it’s not possible, then that’s okay. I just want to know if it’s possible or not.
EDIT: Here’s the database image

>Solution :
Just restructure the array into a format which can be iterated easily. I think you are looking for something like this.
<?php
$results = array_reduce($ce, function($carry, $current) {
$modes = $carry[$current['encounter']]['modes'] ?? [];
array_push($modes, $current['mode']);
$carry[$current['encounter']] = ['modes' => array_unique($modes)];
return $carry;
});
foreach($results as $encounter => $encounterData) {
echo '<div class="encounter">';
echo '<p>' . $encounter . '</p>';
echo '<p>(' . implode(', ', $encounterData['modes']) . ')</p>';
echo '</div>';
}
?>