I'm fairly versed on php, but I need a little help to get my plan of attack correct.
I want a form with two textareas.
In the first textarea will be invoice numbers separated by commas.
In the second textarea will be the matching dollar amounts separated by commas.
I need the two posted variables to separate out the comma separated values, multiply the dollar amount by 2% and find the difference (no problems here I can do this), and spit out a row of data that has
--invoice number --- amount before discount ---- amount after discount ----- discount dollar
I figured the $_post variable is already in an array and I could use that to cycle through the values and do the calculations. Here's what I was playing with real quick, but I kinda thought I was overthinking it and I got a little messy with displaying the data. Thanks for the help.
caldis.php
<?php
$inv = $_POST['invnum'];
$amount = $_POST['price'];
$ggg = $_POST['go'];
if ($ggg == 1) {
echo "<table><tr><td>";
$a = split(',', $inv);
foreach ($a as $value) {
echo($value . "</br> "); // invoice number
}
echo "</td>";
echo "<td>";
$b = split(',', $amount);
foreach ($b as $v) {
$r .= ($v * .02)."</br>"; //discount amount
$paid .= $v - $r ."</br>"; // amount after discount
echo($v . "</br> "); // amount before discount
}
echo "</td>";
echo "<td>";
echo $paid;
echo "</td>";
echo "<td>";
echo $r;
echo "</td>";
echo "</tr></table>";
}
?>
<html>
<body>
<div align="center">
<form method="POST" name="caldis" action="caldis.php">
<table><tr><td>
<textarea name="invnum" cols="50" rows="15" ></textarea>
<textarea name="price" cols="50" rows="15" ></textarea>
<input type="hidden" name="go" size="10" value="1">
<input type="submit" name="submit" value="Calculate">
</td></tr></table>
</form>
</div>
</body>
</html>
- <?php
- $inv = $_POST['invnum'];
- $amount = $_POST['price'];
- $ggg = $_POST['go'];
- if ($ggg == 1) {
- echo "<table><tr><td>";
- $a = split(',', $inv);
- foreach ($a as $value) {
- echo($value . "</br> "); // invoice number
- }
- echo "</td>";
- echo "<td>";
- $b = split(',', $amount);
- foreach ($b as $v) {
- $r .= ($v * .02)."</br>"; //discount amount
- $paid .= $v - $r ."</br>"; // amount after discount
- echo($v . "</br> "); // amount before discount
- }
- echo "</td>";
- echo "<td>";
- echo $paid;
- echo "</td>";
- echo "<td>";
- echo $r;
- echo "</td>";
- echo "</tr></table>";
- }
- ?>
- <html>
- <body>
- <div align="center">
- <form method="POST" name="caldis" action="caldis.php">
- <table><tr><td>
- <textarea name="invnum" cols="50" rows="15" ></textarea>
- <textarea name="price" cols="50" rows="15" ></textarea>
- <input type="hidden" name="go" size="10" value="1">
- <input type="submit" name="submit" value="Calculate">
- </td></tr></table>
- </form>
- </div>
- </body>
- </html>