Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I am working on a rota system, for a local business. The purpose is to allow their staff to enter some criteria and there hours for that month are shown.

    The hours for each employee are uploaded by one admin, these hours are stored in a specially formatted text file.

    An example of a line from the text file would be

    Quote Originally Posted by sample-file.txt
    1 10/03/2007,0900-1700
    1 11/03/2007,1200-1700
    The 1 is the employee number, the next part is the date that employee is due to work and the part after the , is the hours on that day.

    The problem is, the way my script works is that the script will update the row of that specific employee with the last line of the relating shift.

    As in, the column hours for the employee number 1 will always be equal to 11/03/2007,1200-1700 and the line before that will be lost.

    I could of course, query the database, get the value of that user before I update it, concatenate the old value with the value from the file, but this seems backward to me.

    Any other suggestions? Re-developing this small section is not out of the question.

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Most SQL servers offer some sort of method for concatenation; for example, this should work on MySQL:
    Code:
    UPDATE employees SET hours = CONCAT( hours, '11/03/2007,1200-1700' ) WHERE number = 1
    (Note: I haven't actually tested the code, just reconstructing from memory, but I'm fairly certain it'll work fine.)

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Shadowfiend you are a legend.

    I just dummied a row to check, all looks good, I had a quick look through mysql monitor, it looks like each seperate (or subsequent) UPDATE goes onto a new line, but I will have a further look into it.

    Thanks.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    That's probably because you're reading the final newline out of the file. You should be able to use [phpfunction]rtrim[/phpfunction] or even the built-in MySQL RTRIM() function to fix that.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:44 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com