Forum Moderators: coopster
my problem is,, that i have a PHP script that displays a table
the table has the following colums
firstname,surname,boots,hospital,woolworths,br,other, total
the firstname and surname are grabbed from the database when the page loads, what i want is for the user to enter values in the boxes under the colums boots,woolworths,hospital etc
then when they click submit,the page is refreshed, data submited into the database, bu them redisplayed in the table the values are calucated and each user is then given a total number of hours worked at those places.
im really stuck guys, havent a clue how to go about this.
so an example would be
F S boots Hospital woolworths other total
JOE BLOGS 0.8 0.8 0.8 0.8
HELP me 0.1 0.5 0.5 0.5
submit is pressed, data entered into the database, then page redisplayed with the total column totaled up.
F S boots Hospital woolworths other total
JOE BLOGS 0.8 0.8 0.8 0.8 3.2
HELP me 0.1 0.5 0.5 0.5 1.6
please help me.
I am guessing you are overwriting currently the hours for each user and are not able to add the hours to the already existing ones...
the process is three steps
1 - read the current / old hours from database for each user
2 - take the new hours values from the form
3 - add the old and new respectively to get the new total of hours and UPDATE the table
However, that is not what I would recommend...
you can make three tables in fact
A - Employees
B - working hours
C - Destinations / working sites
Employees table may have columns
emp_id (PK)
first_name,
surname
Working Hours table
wid (PK)
emp_id (FK)
dest_id (FK)
hours
date
Destination Table
dest_id (PK)
destination_name
address
submit the working hours in hours table with employee id and destination id and current date. then you can calculate hours for each user like
SELECT SUM(hours) as working_hours FROM hours_table WHERE emp_id=#*$!
it will also facilitate you to search between a specific time period, to change destination and employee attributes without any problem and clean and neat queries too.
also you dont have to rewrite any value you can in fact keep the complete record of the employees' working
the values are entered straight from the from and redisplayed on the form after the submit has been pushed....but the only difference to the table after is has been resisplaed is that the total has been calculated.
so der is nothing about date, id
just a firstname which is always on the page. and whatever values the user has entered into the texboxes under the place they worked.
so hopefully no extra tables, just the 1 table in the database,that mimicin the table headings, that the data gets inserted into, then gets extracted from straight away.
thanks