andrej13 Posted March 8, 2011 Share Posted March 8, 2011 <?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'><option>0</option><option>1</option><option>2</option><option>3</option></select>"; 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> My output is like this cola : 2 Prijs: 4 totaal: 4fanta : 1 Prijs: 2 totaal: 6 but I want it like this cola : 2 Prijs: 4 fanta : 1 Prijs: 2 totaal: 6 Thanks in advance: price = prijs, totaal = total, dranken = drinks Quote Link to comment https://forums.phpfreaks.com/topic/230047-output-problem/ Share on other sites More sharing options...
Muddy_Funster Posted March 9, 2011 Share Posted March 9, 2011 Try moving echo " totaal: $totaalPrijs"; outside the while{} loop (at the end) Quote Link to comment https://forums.phpfreaks.com/topic/230047-output-problem/#findComment-1184927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.