Nieuw lid |
|
De output van de php klopt niet echt goed, wilt iemand mij helpen aub?
Mijn output ziet er bvb zo uit:
cola : 4 Prijs: 8
totaal:8fanta : 1 Prijs: 2
totaal:10
maar graag zou ik het zo willen hebben
cola : 4 Prijs: 8
fanta : 1 Prijs: 2
totaal:10
Mvg !
<?php if (!isset($_POST['submit'])) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<form method="post" action="<?php echo $PHP_SELF; ?>">
<input type="submit" value="Toon Output" name="submit"/>
<?php
$dranken = array("cola", "fanta", "bier", "koffie", "thee");
$prijzen = array("2", "2", "1.80", "2.20", "2.20");
$i = 0;
echo "<table>";
while ($dranken[$i]) {
$listnaam = $dranken[$i] . "_aantal";
$optionlist = "<select name='$listnaam'>\n";
for( $v = 0; $v < 10; $v++ ) {
$optionlist .= "<option value=\"$v\">$v</option>\n";
}
$optionlist .= "</select>\n";
echo "<tr><td >" . $dranken[$i] . "</td>";
echo "<td>" . $prijzen[$i] . "</td>";
echo "<td>" . $optionlist . "</td></tr>";
$i++;
}
echo "</table>";
?>
</form>
<?php
}
$dranken = array("cola", "fanta", "bier", "koffie", "thee");
$prijzen = array("2", "2", "1.80", "2.20", "2.20");
$i = 0;
$totaalPrijs = 0;
while($dranken[$i]) {
$aantal = $_POST[$dranken[$i] . "_aantal"];
if ($aantal > 0) {
$prijsperDrank = $aantal * $prijzen[$i];
echo $dranken[$i] . " : " . $aantal . " Prijs: " . $prijsperDrank . "</br>";
$totaalPrijs += $prijsperDrank;
echo " totaal:" .$totaalPrijs;
}
$i++;
}
?>
</html>
<?php if (!isset($_POST['submit'])) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <form method="post" action=" <?php echo $PHP_SELF; ?>"> <input type="submit" value="Toon Output" name="submit"/> <?php $dranken = array("cola", "fanta", "bier", "koffie", "thee"); $prijzen = array("2", "2", "1.80", "2.20", "2.20"); $i = 0; while ($dranken[$i]) { $listnaam = $dranken[$i] . "_aantal"; $optionlist = "<select name='$listnaam'>\n"; for( $v = 0; $v < 10; $v++ ) { $optionlist .= "<option value=\"$v\">$v</option>\n"; } $optionlist .= "</select>\n"; echo "<tr><td >" . $dranken[$i] . "</td>"; echo "<td>" . $prijzen[$i] . "</td>"; echo "<td>" . $optionlist . "</td></tr>"; $i++; } ?> </form> <?php } $dranken = array("cola", "fanta", "bier", "koffie", "thee"); $prijzen = array("2", "2", "1.80", "2.20", "2.20"); $i = 0; $totaalPrijs = 0; while($dranken[$i]) { $aantal = $_POST[$dranken[$i] . "_aantal"]; if ($aantal > 0) { $prijsperDrank = $aantal * $prijzen[$i]; echo $dranken[$i] . " : " . $aantal . " Prijs: " . $prijsperDrank . "</br>"; $totaalPrijs += $prijsperDrank; echo " totaal:" .$totaalPrijs; } $i++; } ?> </html>
|