PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm building a page in which someone enters weekly data about their progress towards a certain goal. This week's goal description is editable and last weeks success/fail is editable, but everything else is displayed by not editable.
Example
Student Num | This week desc.(editable) | last week s/f(editable) | prev week(not ed.) | prev week(not ed) | etc
The issue is that I want to basically move this weeks description one cell to the right every sunday night and in it's place put up a new description textarea that whose data will be entered into the database.
Anyone have any ideas on how to enable this event on a weekly basis?
Users will be able to edit the fields any time, however. So the php could be inserting things into the database on any day. The difference is that it will keep editing the last record in the database until sunday at midnight, then a new record will be added...hmmm...I think here I see the potential use of a cron...
I don't think you need cron at all.... cron is for running processes at set times. PHP can handle the decisions as to what is to be editted by looking at the date/time of the server and handling the DB queries for particular dates. I assume you store dates in the database too right? I could knock up an example if I got some time to do it
Right now I'm storing the actual date that an edit is created, so this could be any day.
I could add a field that records a particular date, so let's say someone enters some data on wednesday, September 1st, the new field would record the date of the previous sunday...
You would need two timestamps... a "record first created" field, and a "record last edited" field, every time you go to edit it first check the first created field, subtract it from time(), then edit it and update the last edited field.
The reason you subtract it from time() is if the number that gives you is less then the number of seconds in a week, you edit, if it is >= you create a new record instead.
This is if you want to keep a "clean table", or you could just insert a new record for every edit, and just order by the timestamp DESC and limit 1, when you need to get the last edit.. this way you maintain a history of edits in the table, you'll just have a lot of unneeded rows..
Raghavan,
Thanks - it's along the lines of what I'm working on, but that code assumes the user will be entering data every sunday, which isn't always going to happen. It must be that no matter what day the user logs in, if the new week has begun, so to speak. I'm adding a baseline start-date and will need to take that date and compare it to getdate()...
hmmm - and I just thought of an added detail - if someone does not update the system for, say, 3 weeks, the next time they sign in they would see those three weeks with empty fields as well as this week's field to enter data into. I'm thinking that would take date() - $startdate and then a foreach(week) run a loop that prints out an empty description field...But that's just off the top of my head. I'm just learning php, so any hints would be appreciated. Thanks again!