Advertisement
Guest User

ExpenseTable

a guest
Dec 4th, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2. function getMonths()
  3. {
  4.     $months = [];
  5.     $months[] = "<th class='normalMontг'>January</th>";
  6.     $months[] = "<th class='redMonth'>March</th>";
  7.     $months[] = "<th class='redMonth'>October</th>";
  8.     $months[] = "<th class='redMonth'>November</th>";
  9.  
  10.     return $months;
  11. }
  12. ?>
  13. <html>
  14. <head>
  15.     <title>Annual Expenses</title>
  16. </head>
  17. <body>
  18. <form action="" method="post">
  19.     <label for="years">Enter number of years:</label>
  20.     <input type="text" name="years" id="years"/>
  21.     <input type="submit" value="Show costs"/>
  22. </form>
  23. </body>
  24. </html>
  25. <?php if(isset($_POST['years']) && is_numeric($_POST['years'])): ?>
  26. <table border="1">
  27.     <tr>
  28.         <th>Year</th>
  29.         <?php foreach (getMonths() as $monthElement): ?>
  30.             <?= $monthElement; ?>
  31.         <?php endforeach; ?>
  32.         <th>Total:</th>
  33.     </tr>
  34.     <?php for ($year = date("Y"); $year > (date("Y") - $_POST['years']); $year--): $sum = 0 ?>
  35.     <tr>
  36.         <td><?= $year; ?></td>
  37.         <?php for ($i = 0; $i < count(getMonths()); $i++): $currentExpense = rand(0, 99) ?>
  38.             <td><?= $currentExpense; ?></td>
  39.         <?php $sum += $currentExpense; endfor; ?>
  40.         <td><?= $sum; ?></td>
  41.     <?php endfor; ?>
  42.     </tr>
  43. </table>
  44. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement