Currently i’m trying to work on a simple Timesheet for me and my brother. We are both self-employed but we would like to track our hours. I have allready created a simple form where we can fill in our hours etc. This is how the form looks like:
Username(Automatic filled in by login)
Customer
Workday
Weeknumber (automatic from php date)
Hours
Proceedings
Date (automatic from php date)
This part allready works, i can fill everything in and post it to the mysql database. But now i want to display all the data in a table (the mysql table is called timesheet and the columns are called like the form names). But i would also like to have a simple dropdown with the year number and two buttons where we can filter the weeknumber. It should display the data of the current week (php date(“W”)) but with the buttons to choose the next week or previous and i really don’t know how to do this.
You could try creating a form that has the date; then when you submit the form you use that variable in your mysql query to grab the correct timesheet. You could also use Javascript and some AJAX also- but the form method should work fine and is probably easier for you to do.
Why do you ask for workday, week and date? If you know the date you can derive the other two. Having all three fields can lead to confusion. What if the workday is 5, the week is 1 and the date is to 20 of August?
Also, I assume customer is a drop down list so you avoid making typing errors? (ie. blue company vs bleu company)
As for your query,
SELECT
date
, username
, hours,
, proceedings
, customer
FROM
timesheet
WHERE
date >= ?
AND date < ?
Where the question marks must be replaced with the first day of the current week and the first day of next week, respectively (or keep the question marks for a prepared statement, even better!)
As for the switching buttons, just supply the new date as a $_GET parameter and work it out from there (<a href="/timetable.php?start=2014-03-17">prev</a> <a href="/timetable.php?start=2014-03-31">next</a>, something like that).