Mehrere SELECT-Felder überprüfen

EuroCent

Klappstuhl 2.0
Hallo zusammen :)

Wie einmal sitze Ich vor einem Problem, entweder bin Ich da nur zu Doof dafür, oder Ich mache eindeutig etwas falsch oO

Mein Problem ist folgendes:
Ich habe ein Formular, welches mehrere SelectFelder mit dem selbigen Inhalt hat.
Nun möchte Ich via PHP abfragen was in den Vars enthalten ist, also ob -1 oder entsprechend das value was in den Optionen hinterlegt ist.

Mein Code:
PHP:
$getteam = __getTeamtag($_SESSION['user']);
$teamname = __getTeam($_SESSION['user']);

$sql = $db->__query("SELECT * FROM tk_agents WHERE getteam = '{$getteam}'");
$table = '';
$count = 0;
$checkSum = 0;

while($row = $db->__fetchArray($sql)) {
    $username = $row['username'];
    $username = explode(".", $username);
    $uname = $username[1];
    $count+= 1;
 
    $table .= '<tr>'."\n";
        $table .= '<td>'.$uname.'</td>'."\n";
        $table .= '<td>'.$row['personal'].'</td>'."\n";
        $table .= '<td>'."\n";
            $table .= '<select name="atyp_'.$count.'" id="atyp_'.$count.'" class="form-control">'."\n";
                $table .= '<option value="-1">--- Bitte w&auml;hlen ---</option>'."\n";
                $table .= '<option value="1">06:00 bis 14:12</option>'."\n";
                $table .= '<option value="2">06:25 bis 14:37</option>'."\n";
                $table .= '<option value="3">14:20 bis 22:32</option>'."\n";
                $table .= '<option value="4">14:45 bis 22:57</option>'."\n";
                $table .= '<option value="5">Krank mit Attest</option>'."\n";
                $table .= '<option value="6">Krank ohne Attest</option>'."\n";
                $table .= '<option value="7">Urlaub</option>'."\n";
                $table .= '<option value="8">Elternzeit</option>'."\n";
                $table .= '<option value="9">Berufsschule</option>'."\n";
                $table .= '<option value="10">... weitere ...</option>'."\n";
            $table .= '</select>'."\n";
        $table .= '</td>'."\n";
        $table .= '<td>...</td>'."\n";
    $table .= '</tr>'."\n";
 
    $checkSum++;
}

Hier hab Ich dann mittels einer For-Schleife versucht den Inhalt auszugeben:
PHP:
if(isset($_POST['sendDaily'])) {
    for($i = 1; $i <= $checkSum; $i++) {
        if($_POST['atyp'.$i]) echo $i.": Gesetzt<br />";
        else echo $i.": nicht Gesetzt<br />";
    }
}

Hier bekomme Ich immer den else-Wert geliefert, selbst wenn 1 oder mehrere Select-Felder ausgewählt wurden.

Aus probiert hab Ich auch dieses:
PHP:
$getteam = __getTeamtag($_SESSION['user']);
$teamname = __getTeam($_SESSION['user']);

$sql = $db->__query("SELECT * FROM tk_agents WHERE getteam = '{$getteam}'");
$table = '';

while($row = $db->__fetchArray($sql)) {
    $username = $row['username'];
    $username = explode(".", $username);
    $uname = $username[1];
 
    $table .= '<tr>'."\n";
        $table .= '<td>'.$uname.'</td>'."\n";
        $table .= '<td>'.$row['personal'].'</td>'."\n";
        $table .= '<td>'."\n";
            $table .= '<select name="atyp[]" id="atyp" class="form-control">'."\n";
                $table .= '<option value="-1">--- Bitte w&auml;hlen ---</option>'."\n";
                $table .= '<option value="1">06:00 bis 14:12</option>'."\n";
                $table .= '<option value="2">06:25 bis 14:37</option>'."\n";
                $table .= '<option value="3">14:20 bis 22:32</option>'."\n";
                $table .= '<option value="4">14:45 bis 22:57</option>'."\n";
                $table .= '<option value="5">Krank mit Attest</option>'."\n";
                $table .= '<option value="6">Krank ohne Attest</option>'."\n";
                $table .= '<option value="7">Urlaub</option>'."\n";
                $table .= '<option value="8">Elternzeit</option>'."\n";
                $table .= '<option value="9">Berufsschule</option>'."\n";
                $table .= '<option value="10">... weitere ...</option>'."\n";
            $table .= '</select>'."\n";
        $table .= '</td>'."\n";
        $table .= '<td>...</td>'."\n";
    $table .= '</tr>'."\n";
}

Hier hatte Ich mit einer foreach-Schleife es versucht :/ :
PHP:
foreach($_POST['atyp'] as $value => $key) { var_dump($value[$key]); }

foreach($_POST['atyp'] as $value) { var_dump($value); }

Leider bekomm Ich einen invalid foreach ins gesicht geworfen :/

Mache Ich grundlegend etwas falsch beim Erstellen des Selectfeldes oder ist der Ansatz zwar da, aber die Umsetzung fehlerhaft?
 
gibt es auch null zurück, wenn du im letzen Dropdown einen Wert auswählst?

Was mir nur aufffällt, dass du keien Auswertung hast, für welchen MA die Angabe gilt. Das Framework welches ich hauptsächtlich nutze baut die Namen immer wie folgt auf:

PHP:
name = "custom_name[1][field_name]"

Von daher würde ich es ähnlich bei dir machen:

PHP:
$table .= '<select name="atyp['.$row['id'].']" id="atyp_'.$row['id'].'" class="form-control">'."\n";"

So hasst du die Zuodnung des Auswahl zu der ID von tk_agents. Ich habe die ID auch an das Attribut ID gehangen. Die ID sollte innerhalb eines Formular unique sein.
 
Habe meinen Fehler gefunden... :/
Der Fehler war, dass Ich die Selections nicht in den FORM-Tag eingebunden hatte...

Daher konnte es nie zu einem Ergebnis führen ;/
Erst als ich:
PHP:
printf("<pre>%s</pre>", print_r($_POST));
ausführte, habe Ich den Fehelr erkannt :D
 

Neue Beiträge

Zurück