function sum_variable_exp($id, $begin) { global $connection; $date = date_prep($begin); $query = "SELECT SUM(amount) FROM (SELECT amount FROM check_book "; $query .= " WHERE expense_id = " . $id; $query .= " AND date >= '{$date}' "; $query .= ") AS subquery"; $sum = mysql_fetch_array(mysql_query($query, $connection)); return $sum['SUM(amount)']; }
</h2> <hr/> <p style = "float: left;"><a href= ../blog/logout.php>Log Out</a></p> <form style = "float: right; border: none;" method = "post"> <p>View Transactions for: <?php echo month_selector($thismonth); ?> <input type="submit" name= "go_to" value="Go!" /></p> </form> <hr style = "clear: both;"/> <?php $begin_query = date_prep(mktime(0, 0, 0, $_GET[mon], 1, $_GET[yr])); $last_date = $_GET[mon] + 1; $end_query = date_prep(mktime(0, 0, 0, $last_date, 0, $_GET[yr])); $query1 = "SELECT SUM(amount)\n FROM (SELECT amount FROM check_book\n WHERE date < \"{$begin_query}\"\n ) AS subquery"; ?> <table id = check_book> <tr> <th>Date</th> <th>Type</th> <th>Expense</th> <th>Cleared?</th> <th>Amount</th> <th>Balance</th> <th>Budgeted As?</th> <th>Edit</th> </tr> <?php
<?php $today = mktime(0, 0, 0, date("m"), date("d"), date("Y")); //month of today $month = date("m", $today); //last day of this month $temp_eom = mktime(0, 0, 0, $month + 1, 0, date("Y")); //find the pay day at the end of the month $temp_eom_payday = check_weekend($temp_eom); $fixed_eom = date_prep($temp_eom_payday); //test to see if we need to go to the next budget month... if (date_prep($today) >= $fixed_eom) { $thismonth = $month + 1; if (strlen($thismonth) == 1) { $thismonth = "0" . $thismonth; } } else { $thismonth = $month; } //return the first day of the budget month $first_budget_mo = mktime(0, 0, 0, $thismonth, 0, date("Y")); $first = date("n/d/y", check_weekend($first_budget_mo)); //return the mid month pay day $mid_budget_mo = mktime(0, 0, 0, $thismonth, 15, date("Y")); $mid = date("n/d/y", check_weekend($mid_budget_mo)); //return the last day of budget month $last_budget_mo = mktime(0, 0, 0, $thismonth + 1, 0, date("Y")); $last_budget_mo = check_weekend($last_budget_mo) - 60 * 60 * 24; $last = date("n/d/y", $last_budget_mo); //determine total number of days in budget month $total_days = 1 + date_diff(check_weekend($last_budget_mo), check_weekend($first_budget_mo));