getMessage(); } $query = "SELECT Id,LevelName FROM levels"; $levels = PDO_FetchAssoc($query); $query = "SELECT * FROM levels"; $levelsAll = PDO_FetchAll($query); $query = "SELECT monstats.Id, strings.String AS Name FROM monstats LEFT JOIN strings ON monstats.NameStr = strings.Key;"; $monstats = PDO_FetchAssoc($query); //ddump($monstats); $query = "SELECT LevelName,Vis0,Vis1,Vis2,Vis3,Vis4,Vis5,Vis6,Vis7 FROM levels"; $res = PDO_FetchAll($query); $output = []; foreach ($res as $key => $item) { $newItem = []; $newItem['LevelName'] = $item['LevelName']; // Copy the LevelName to new item foreach ($levelsAll[$key] as $levelsKey => $levelsValue) { $newItem[$levelsKey] = isset($monstats[$levelsValue]) ? $monstats[$levelsValue] : $levelsValue; } $foundLevels = []; // Store found level names to avoid duplicates foreach ($item as $subKey => $subItem) { // Check if the key starts with 'Vis', has a corresponding level, is non-empty, and is not a duplicate if (strpos($subKey, 'Vis') === 0 && isset($levels[$subItem]) && $levels[$subItem] !== '' && !in_array($levels[$subItem], $foundLevels)) { $newItem[$subKey] = "(" . $subItem . ") " . $levels[$subItem]; $foundLevels[] = $levels[$subItem]; // Add to found levels } } $output[] = array_filter($newItem); // Add the modified item to the output array } unset($output[0]); ddump($output); ?> Levels Table "; // Display table headers with Bootstrap styling $headers = ['Id', 'Name', 'LevelName']; for ($i = 0; $i < 8; $i++) { $headers[] = "Vis" . $i; } for ($i = 1; $i <= 25; $i++) { $headers[] = "mon" . $i; } $headers[] = 'MonDen'; echo ""; // Add thead and use Bootstrap dark theme echo ""; foreach ($headers as $header) { echo "" . $header . ""; } echo ''; echo ""; // Display table data with Bootstrap styling echo ""; foreach ($output as $level) { echo ""; foreach ($headers as $header) { if (isset($level[$header])) { echo "" . $level[$header] . ""; } else { echo ""; } } echo ""; } echo ""; // End the HTML table echo ""; ?>