Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>My Bills</title>
- </head>
- <body>
- <h1>My Bills</h1>
- <form method="post">
- <h2>Sort Order for Items:
- <?php
- $sort_order = $_POST['sort_order'];
- $target_string = $_POST['targetstring'];
- $targe_string = trim($target_string);
- $total = 0;
- $error_cnt = 0;
- echo "<span id=\"order\">Ascending <input type=radio name=sort_order value=ascending checked> \n";
- echo "Descending <input type=radio name=sort_order value=descending> </span></h2>\n";
- $bills_array = array();
- for ($i = 1; $i < 5; $i++) {
- $item_name = 'item_name' . $i;
- $item_value = $_POST[$item_name];
- $amount_name = 'amount_name' . $i;
- $amount_value = $_POST[$amount_name];
- $amount_value = trim($amount_value);
- $bills_element = "$item_value*$amount_value*";
- array_push($bills_array, $bills_element);
- }
- if ($sort_order == 'descending') {
- rsort($bills_array);
- } else {
- sort($bills_array);
- }
- ?>
- <br /><b>Find items that contain:</b>
- <input type="text" name="targetstring" size="20"><br /><br />
- <table>
- <tr>
- <th>Item</th>
- <th>Amount</th>
- </tr>
- <?php
- for ($i = 1; $i < 5; $i++) {
- $item_name = 'item_name' . $i;
- $item_value = $_POST[$item_name];
- $amount_name = 'amount_name' . $i;
- $amount_value = $_POST[$amount_name];
- $amount_value = trim($amount_value);
- $array_counter = $i - 1;
- $item_value_from_array = $item_value;
- $item_value_from_array = $bills_array[$array_counter];
- list($item_value_from_array, $amount_value) = explode("*", $bills_array[$array_counter]);
- echo "<tr>\n";
- $style = "";
- if (!empty($target_string)) {
- $pos = strpos($item_value_from_array, $target_string);
- if ($pos !== false) {
- $style = ' style="background-color: Yellow;"';
- }
- }
- echo "<td><input type=text name=" . $item_name . " value=" . $item_value_from_array . "$style></td>\n";
- echo "<td><input type=text name=" . $amount_name . " value=" . $amount_value . "$style></td>\n";
- if (!empty($amount_value)) {
- if (is_numeric($amount_value)) {
- $total = $total + $amount_value;
- } else {
- echo "<td><font color=red> ERROR: " . $amount_value . " is not a number.</font></td>\n";
- $error_cnt++;
- }
- }
- echo "</tr>\n";
- }
- ?>
- </table>
- <?php
- if ($error_cnt > 0) {
- echo "<font color=red><p>Errors: " . $error_cnt . "</font></p>\n";
- } else {
- echo "<font color=green><p>Total Amount For All Bills: $total</font></p>\n";
- }
- ?>
- <br><input type="submit" value="Submit">
- <br />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement