PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : PHP: Werte aus dynamischen Selectboxen



Demo
25-03-2005, 15:41
Hi,

ich steh grad maechtig auf dem Schlauch. Ich hab hier ein Skript, das eine bestimmte Anzahl Selectboxen erstellt, diese mit Werten fuellt. Die ausgewaehlten Werte der Selectboxen sollen nun in eine Datenbank eingetragen werden. Aufgrund meiner momentanen Konfusitaet bin ich mir absolut nicht mehr sicher, wie ich die Werte aus den Selectboxen rausbekomm. Er traegt zwar was ein, aber das sind immer die Zahlen der for Schleife.

Hier mal das Skript:


<html>
<head>
<title>Play-Off Teams auswaehlen</title>
</head>

<?php
require_once("playoff.php");
//error_reporting(E_ALL);
$myPO = new playoffs();

$selectArray = array("team1","team2","team3","team4","team5","team6","team7","team8");
$imagearray= array("logo1","logo2","logo3","logo4","logo5","logo6","logo7","logo8","logo9","logo10","logo11","logo12","logo13","logo14","logo15","logo16");
?>
<!-- play-off mode integrieren -->

<body>
<table cellpadding="0" cellspacing="0" border="0">
<form method="POST" action="<?php echo $PHP_SELF; ?>">
<tr>
<td>Play-Off Modus:</td>
<td><?php $myPO->selectStuffFromDB("poMode"); ?></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="po" value="auswaehlen"></td>
</tr>
</table>
<?php
if((isset($_POST['po'])) AND (isset($_POST['poMode']))){
$k =0;
$array = explode(" ",$poMode);
//echo $array[0];
switch($array[0])
{
case "Achtelfinale" : $k = 16;
break;
case "Viertelfinale": $k = 8;
break;
case "Halbfinale" : $k =4;
break;
case "Finale": $k=2;
break;
}

echo "<table cellpadding='0' cellspacing='0' border='1'>
<form method='POST' action='$PHP_SELF'>";

for($i=0;$i<$k;$i++){
$j=$i+1;
echo "<tr>
<td>$j . Team:</td><td><select name='team$i'>";
$myPO-> unionTeams("teamname","ligateams_mrA","ligateams_mrB");
echo "</td><td>Logo URL:</td><td><input type='text' name='$imagearray[$i]'></td>
</tr>";
}
echo "<tr><td colspan='4'><input type='hidden' name='k' value='$k'></td></tr>
<tr><td colspan='4'><input type='hidden' name='mode' value='$array[0]'></td></tr>";

echo "
<td colspan='2'><input type='submit' name='do' value='anlegen'></td>
</form>
</table>";

}
?>

<?php
if(isset($_POST['do'])){
$l = $k-1;
for($i=0;$i<=$l;$i++){
echo $selectArray[$i];
echo "gg:".$team $i." hhhh";
$myPO->writePOTeams($team.$i,$imagearray[$i],$mode);
}
}


?>


</body>
</html>


das ich mit $imagearray[$i] in writePOTeams Kaese mache weiss ich ;)

die dazugehoerigen Klassenfunktionen:


/*---schnippp----------- */

function unionTeams($selectwhat,$table1,$table2)
{
$sql = "SELECT ".$selectwhat." FROM ".$table1." UNION SELECT ".$selectwhat." FROM ".$table2.";";
$auswahl = $this->resultQuery($sql);
//echo "<select name='$selectname'>";
while($row=mysql_fetch_array($auswahl)){
extract($row);
echo "<option>".$teamname."</option>";
}
// echo "</select>";
}

function writePOTeams($team,$image,$mode)
{
$sql = "INSERT INTO poTeams (teamname,teamimage,poMode) VALUES('$team','$image','$mode');";
$this->generalSQLActions($sql);
}
Kann mir da einer von Euch mal bitte auf die Spruenge helfen ?

Danke und Gruss,

undefined
25-03-2005, 18:06
Wirkt immer Wunder wenn man bei Array's nicht mehr durchblickt ;)


echo "<pre>";
var_dump( $_POST);
echo "</pre>";