SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    append to table instead of overwriting data

    I have a php page that inserts data into a database.
    Code:
    mysql_query("insert into job_log VALUES ('','$emp_id','$project','', '$now','$clock_actions','$domain')", $db_link);
    The problem is I also need the data inserted into a new table with duplicate fields and insted of the data being overwritten, I need the newest data appened to the table.
    I have tried update but havent been able to get it to work.
    Code:
    mysql_query("update job_log_time VALUES ('','$emp_id','$project','', '$now','$clock_actions','$domain')", $db_link);
    examples:

    currently:

    table 1
    emp_id time action
    1 8.00 clock in
    2 8.00 clock in

    when the employee performs a new action the data is overwritten

    table1
    emp_id time action
    1 10.00 break
    2 10.03 break

    ************************
    what I need is this:

    table1
    emp_id time action
    1 8.00 clock in
    2 8.00 clock in
    1 10.00 break
    2 10.03 break

  2. #2
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I took over the site after my predecessor "left". Here is the complete insert code if that helps:

    Code:
    if ($action_submit){
    
    		$now=(mktime()-21600);
    
    		$emp_id = $row_user['employee_id'];
    
    		$domain = GetHostByName($REMOTE_ADDR);
    
    		mysql_query("insert into job_log VALUES ('','$emp_id','$project','', '$now','$clock_actions','$domain')", $db_link);
    
    		mysql_query("insert into job_log_time VALUES ('','$emp_id','$project','', '$now','$clock_actions')", $db_link);

  3. #3
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UPDATE is for updating the values in existing rows. If you want to append data to a table, you have to use INSERT.

    What exactly are you trying to accomplish? Not in technical language, but the way you would describe it to a non-technical person.

    Why do you need to duplicate the data in another table? What is the justification for this?

  4. #4
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the people i work for are knuckle draggin gombas!!
    they want to keep track of all the employees working habits

    a day in the life of one of my users:

    arrive at 8:00 am, log into company site and click "begin work" (literally, that's what they wanted the button labeled)

    10:00 click "break out"
    10:15 click "break in"

    12:00 click "lunch out"

    etc. etc.

    I have a page that will pull the data and display:
    userid--clock action
    1--------clock in 8:00
    2--------clock in 8:00
    1--------break out 10:00
    2--------break out 10:03
    1--------break in 10:15
    2--------break in 10:18

    eventually they want me to build a php page that will automatically add all working time

    It has to be a new table because one of the big wigs heard "if you go adding fields and databases to existing tables you could corrupt the information" (yes thats exactally how he said it)

    unfortunately his son, who just started here, knows just enough to check up on me.

  5. #5
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sincerely apologize, I have several projects going at once and I "combined" two of them in my head. I am sorry if I wasted anyones time.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •