Hallo.
Ich hab mir ein Script geschrieben (also einmal damit angefangen), wo man games für meinen quizbot erstellen kann.
ich hab das folgendermaßen gemacht:
PHP-Code:
<html>
Wieviele Fragen wollen Sie erstellen?
<form action="<?php echo $PHP_SELF; ?>" method="post">
<input type="text" name="anzahl">
<input type="submit" name="sub" value="Enter"></form>
</html>
<?
if($sub)
{
$max = 25;
$wert = $anzahl;
if($wert > $max)
{
echo "Maximal 25!";
}
if($wert <= $max)
{
echo "<form action='$PHP_SELF' method='post'>";
for($anzahl2 = 0; $anzahl2 < $wert; $anzahl2++)
{
echo "<input type=\"text\" name=\"frage[$anzahl2]\" >";
echo "<input type=\"text\" name=\"antwort[$anzahl2]\" ><br>";
}
echo "<input type=\"submit\" name=\"sub2\" value=\"Enter\"></form>";
}
}
if($sub2)
{
for ($i = 0; $i <= $wert; $i++)
{
echo $frage[$i];
echo $antwort[$i];
}
}
?>
allerdings habe ich ein problem:
wenn ich jetzt die fragen eingebe .. und sie dann wie am schluss ausgeben will, wird nur die erste frage angezeigt.
ich glaube das problem ist, dass die variable ($wert) nur innerhalb der if($sub) anweisung gespeichert wird.
weil wenn ich nach if($sub2) --> echo $wert; mach, gibt er mir nichts zurück, daher gibt er auch nur eine frage aus, weil $i = 0 und da $wert nicht vorhanden ist, zählt er nicht weiter rauf und bleibt auf 0.
mfg