Hi Folks
I am having some real difficulty working this one out and I hope someone can assist.
I have a table with fields as follows:
id, userid, name, amount, nextdue, frequency
(The frequency field contains an integer from another table with options: weekly(1), fortnightly(2), monthly(3), quarterly(4) and annually(5))
What the user will do is select a number of weeks (‘x’) (i.e.4,8,12 etc) and from this I want to build a table with ‘x’ number of columns, each being one week, starting from todays date.
i.e. col1 = today’s date to (today’s date + 6)
col2 = (today’s date+7) to (today’s date + 13)
col3 = (today’s date+14) to (today’s date + 20) etc etc
Then I want to iterate through each record from the above table and insert the ‘amount’ field into each column where this amount would be due, given the columns date range, and the frequency of the records. If the amount does not fall due within that columns date range, a $0.00 would be inserted.
So say for example that a record has a nextdue date of today and a frequency of ‘1’ (being weekly). This would insert that amount into every column across the table because this amount will fall due once a week. A monthly frequency with a nextdue date of today will show in the first column, then approximately every 4th column after that. I hope that makes sense
Then at the bottom I would like to total each column.
What I am thinking is that I will put the values into textboxes and setup an event to update the totals box using javascript so that a user can change the values in the table and see how the total amounts will change.
My first problem though is that I cannot get the table setup so the amounts are being inserted into the right columns to start with, and that they are then being totalled properly.
Here is where I am at currently:
A simple form getting the number of columns for the table:
[code][
4 Weeks 8 Weeks 12 Weeks [/code] On submit I run a script to update the nextdue field. This uses the current nextdue value and using the frequency field, calculates the next date that this record would be due and updates the db field.Now I want to build my table:
[php]
<?php $totals = array(); $todaysdate = mktime(0,0,0,date("m"), date("d"), date("y")); for($k=0; $k < ($_POST['numWeeks']); $k++) { if($k == 0){ echo " | " . date("d-m-y",($todaysdate+($k * 604800))) . " to " . date("d-m-y",($todaysdate+518400)) . " | "; } else { echo "" . date("d-m-y",($todaysdate+($k * 604800))) . " to " . date("d-m-y",($todaysdate+($k * 604800)+518400)) . " | "; } } echo "
---|---|---|
" . $row['name'] . " | "; [/php] This gives me a simple table with a first column with the name field and then $_POST['numWeeks'] number of columns with weekly date ranges. This is also where I start having trouble. How do I then iterate through the date ranges for each record, inserting the value where appropriate? Any help will be greatly appreciated!