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; $foundLevels[] = $levels[$subItem]; // Add to found levels } } $output[] = array_filter($newItem); // Add the modified item to the output array } unset($output[0]); ?> Levels Table CRUD '; // Start the HTML table with Bootstrap's table classes echo ''; // Display table headers $headers = ['Id', 'LevelName', 'Name']; for ($i = 0; $i < 8; $i++) { $headers[] = "Vis" . $i; } echo ""; foreach ($headers as $header) { echo ""; } echo ""; // Display table data echo ""; foreach ($output as $level) { echo ""; foreach ($headers as $header) { if ($header === 'Id' || $header === 'LevelName' || $header === 'Name') { echo ""; } else { // For the VisX fields, display dropdowns echo ""; } } echo ""; } echo ""; echo '
" . $header . "
" . (isset($level[$header]) ? $level[$header] : '') . ""; echo ""; echo "
'; // Close the form echo ''; ?>