PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : checkbox auswahlliste



Travolds
31-01-2005, 13:43
hallo,

ich hab folgendes vor:

eine Tabelle (HTML) mit mehreren Zeilen.
in jeder zeile



<table>
<tr>
<td><input type=text name=name[] value="auto"></td>
<td><input type="checkbox" name="check[]" value="1">
</tr>
<tr>
<td><input type=text name=name[] value="bus"></td>
<td><input type="checkbox" name="check[]" value="1">
</tr>
<tr>
<td><input type=text name=name[] value="bahn"></td>
<td><input type="checkbox" name="check[]" value="1">
</tr>
</table>


annahme:
es wird nun "auto" und "bahn" aktiviert

in php dann:



$Name = $_REQUEST['Name'];
$AddBox = $_REQUEST['check'];

reset($Name);
reset($AddBox);

print "Data:<br>============<br><br>";

$nI = 0;

$LineCount = count($FileName);

for ($nI = 0; $nI < $LineCount; $nI++) {
print "<br>Etappe $nI";
print "<br>Name: $Name[$nI]";
print "<br>check: $AddBox[$nI]";

if ($AddBox[$nI] == 0) {
print "nicht markiert<br>";
}
}


das problem ist ja nun, dass das array AddBox nur 2 statt 3 Werte besitzt. Meine Frage nun:

Wie kann man das gescheiter machen?!? :confused:

Erreichen möchte ich etwas ähnliches, wie man es schon von GMX her kennt, mails markieren und dann die markierten einträge löschen.

hab schon sufu und etliche boards durchsucht aber anscheinend nicht die richtigen suchbegriffe gefunden.

hat da jemand ne idee? :rolleyes:

wäre für jede hilfe dankbar.

lg :travolds

BlueJay
31-01-2005, 14:17
Also, ich würde es folgendermaßen machen:

Variante 1:
die Checkboxen bekommen verschiedene Values, auf die abgefragt werden kann, z.B. 1,2,4


Variante 2:
<input type="checkbox" name="auto" value="1"> Auto<br>
<input type="checkbox" name="Bus" value="2"> Bus<br>
<input type="checkbox" name="Bahn" value="4"> Bahn<br>

im php-Teil:
if (isset($_REQUEST("auto")) ...
if (isset($_REQUEST("bus")) ...
if (isset($_REQUEST("bahn")) ...

chaqu'un a son gout!

so long,
BlueJay

sixfriends
31-01-2005, 22:24
Ist das einfachste, was mir momentan einfällt:

<table>
<tr>
<td><input type=text name=name[] value="auto"></td>
<td><input type="checkbox" name="check0" value="1">
</tr>
<tr>
<td><input type=text name=name[] value="bus"></td>
<td><input type="checkbox" name="check1" value="1">
</tr>
<tr>
<td><input type=text name=name[] value="bahn"></td>
<td><input type="checkbox" name="check2" value="1">
</tr>
</table>
if (!empty($_REQUEST['check'.$i]))
ergibt true, wenn name[$i] checked

Gaert
03-02-2005, 09:02
Ist das einfachste, was mir momentan einfällt...

Noch etwas schöner...



<form method="post">
<table>
<tr>
<td><input type=text name="text[auto]" value="auto"></td>
<td><input type="checkbox" name="check[auto]" value="1">
</tr>
<tr>
<td><input type=text name="text[bus]" value="bus"></td>
<td><input type="checkbox" name="check[bus]" value="1">
</tr>
<tr>
<td><input type=text name="text[bahn]" value="bahn"></td>
<td><input type="checkbox" name="check[bahn]" value="1">
</tr>
</table>
</form>
<?php
foreach($_POST['check'] as $key=>$value) {
if ($value) {
echo 'Checked Text: ' . $_POST['text'][$key] . '<br/>';
}
}
?>

Pingu
03-02-2005, 09:21
oder ganz anders ...



<form method="post">
<table>
<tr>
<td><input type="checkbox" name="check[]" value="Auto">Auto</td>
</tr>
<tr>
<td><input type="checkbox" name="check[]" value="Bus">Bus</td>
</tr>
<tr>
<td><input type="checkbox" name="check[]" value="Bahn">Bahn</td>
</tr>
</table>
</form>
<?php
sort(($_POST['check']);
foreach($_POST['check'] as $value) {
if ($value) {
echo 'Checked Text: ' . $value . '<br/>';
}
}
?>


Pingu

Travolds
07-02-2005, 15:45
hi,

ich sag mal danke für die antworten.

habs jetzt folgendermaßen gelöst:

ich hab den tipp mit der nummerierung hergenommen. da ich über das checkboxfeld bezug auf die andren input felder nehmen wollte (checkboxnummerierung = index im array) hab ich alle felder in arrays gelesen und ein hilfsarray mit den index werten gemacht.

nun kann ich ganz einfach in der for schleife die einzelnen einträge durch gehn.

wenns interessiert hier der code:



/* read vars from HTML */
$FileName = $_REQUEST['FileName'];
$Titel = $_REQUEST['Titel'];
$AddBox = $_REQUEST['Check'];

/* check -> is something marked by user */
if (is_array($AddBox) == FALSE) {
print "Bitte wählen Sie einen Eintrag";

return 0;
}

/* reset all read arrays */
reset($FileName);
reset($Titel);
reset($AddBox);

/* get count of vars */
$LineCount = count($FileName);

/* get all checkboxes to new array */
$ChkBox = array();

foreach($AddBox as $Idx=>$Var) {
$ChkBox[$Var] = $Var;
print "<br>every new element: $ChkBox[$Var] = $Var";
}

/* reset array */
reset($ChkBox);

for ($nI = 0; $nI < $LineCount; $nI++) {
/*** HIER BEARBEITUNG ***/
/* should not be inserted */
if (!isset($ChkBox[$nI])) {
continue;
}

/* you can easy access var array */
$FileName[$nI] ......
}


ich bitte mich nicht zu steinigen falls es irsinniger quatsch ist ... :rolleyes:

vielen dank nochmal

lg :)