Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getMonths()
- {
- $months = [];
- $months[] = "<th class='normalMontг'>January</th>";
- $months[] = "<th class='redMonth'>March</th>";
- $months[] = "<th class='redMonth'>October</th>";
- $months[] = "<th class='redMonth'>November</th>";
- return $months;
- }
- ?>
- <html>
- <head>
- <title>Annual Expenses</title>
- </head>
- <body>
- <form action="" method="post">
- <label for="years">Enter number of years:</label>
- <input type="text" name="years" id="years"/>
- <input type="submit" value="Show costs"/>
- </form>
- </body>
- </html>
- <?php if(isset($_POST['years']) && is_numeric($_POST['years'])): ?>
- <table border="1">
- <tr>
- <th>Year</th>
- <?php foreach (getMonths() as $monthElement): ?>
- <?= $monthElement; ?>
- <?php endforeach; ?>
- <th>Total:</th>
- </tr>
- <?php for ($year = date("Y"); $year > (date("Y") - $_POST['years']); $year--): $sum = 0 ?>
- <tr>
- <td><?= $year; ?></td>
- <?php for ($i = 0; $i < count(getMonths()); $i++): $currentExpense = rand(0, 99) ?>
- <td><?= $currentExpense; ?></td>
- <?php $sum += $currentExpense; endfor; ?>
- <td><?= $sum; ?></td>
- <?php endfor; ?>
- </tr>
- </table>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement