Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--Write a PHP script AnnualExpenses.php that receives n years from an input HTML form and creates a table with random expenses by months and the corresponding years (n years back). For example, if N is 10, create a table that shows the expenses for each month for the last 10 years. Add a "Total" column at the end, showing the total expenses for the same year. The random expenses in the table should be in the range [0β¦999]. Styling the page is optional.-->
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta charset="UTF-8"/>
- <title>Show Annual Expenses</title>
- <style type="text/css">
- table, th, td {
- border: 1px solid #000;
- }
- </style>
- </head>
- <body>
- <form method="post">
- <p>
- <label for="number-years">Enter number of years:</label>
- <input type="number" name="yearsNum" id="number-years" min="1" max="50" required/>
- <input type="submit" value="Show costs"/>
- </p>
- </form>
- <table>
- <thead>
- <tr>
- <th>Year</th>
- <th>January</th>
- <th>February</th>
- <th>March</th>
- <th>April</th>
- <th>May</th>
- <th>June</th>
- <th>July</th>
- <th>August</th>
- <th>September</th>
- <th>October</th>
- <th>November</th>
- <th>December</th>
- <th>Total</th>
- </tr>
- </thead>
- <tbody>
- <?php
- if (!array_key_exists('yearsNum', $_POST) || intval($_POST['yearsNum']) <= 0) {
- die('The Form can\'t been Empty!!!');
- }
- $yearsNum = (int)$_POST['yearsNum'];
- $currentYear = (int)date("Y", time());
- for ($i = $currentYear - 1; $i >= ($currentYear - $yearsNum); $i--) {
- $total = 0;
- ?>
- <tr>
- <td><?= $i ?></td>
- <?php
- for ($j = 0; $j < 12; $j++) {
- $month_expenses = rand(0, 999);
- $total += $month_expenses;
- echo "<td>$month_expenses</td>";
- }
- ?>
- <td><?= $total ?></td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement