Jump to content

output problem


andrej13

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/230047-output-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.