How can I update existing records from an uploaded list of records?

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
Opie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Jun 22, 2006 7:32 pm
Contact:

How can I update existing records from an uploaded list of records?

Post by Opie » Sun Oct 21, 2007 3:37 am

First off, I hope that title makes sense.  If not, keep reading. ;)

I'm working on a component / module for an intranet based site.  The component provides a list of the currently open projects the company is working on.  Each week a hard copy of this list is provided to all employees.  I'm looking to provide a method for employees to search the list electronically, instead of having to scan a hard copy for a current project number.

I have the front end component built, for the most part.  I'm still tweaking bits and pieces.  I've also developed a module to display a smaller list of certian projects.

My delimma is how to update the project list each week.  I do not want to have to enter each project one at a time via a form.  I would like to provide a csv or sql file for the time being to insert new projects and update existing projects.  The updating of the existing projects is what has me stumped at the moment.  If an existing project is no longer on the list, it needs to be marked as closed.  I have the field for it.  I just do not know how to automate this part.

Any ideas would be helpful.  ~patiently waiting~
http://springhillalumni.org • Springhill High School Alumni Association

User avatar
bascherz
Joomla! Intern
Joomla! Intern
Posts: 86
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: How can I update existing records from an uploaded list of records?

Post by bascherz » Sun Oct 21, 2007 4:18 am

If you haven't found one yet, there are a number of open source PHP scripts available to import your CSV file (check phpclasses.org... loaded with pop-up ads, but also loaded with gobs of great and nicely indexed scripts). As for removing the closed items from the table, that can be done by simply dropping all the records in the table before importing the new CSV file. A cleaner way to do this is to use a temporary table with the same schema until it can be confirmed that the import worked. Then drop all the old records and copy the new ones into the permanent table. This may be oversimplifying the problem, but it seems to address your need.
__________________
Bruce Scherzinger

Opie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Jun 22, 2006 7:32 pm
Contact:

Re: How can I update existing records from an uploaded list of records?

Post by Opie » Sun Oct 21, 2007 6:04 pm

bascherz wrote:If you haven't found one yet, there are a number of open source PHP scripts available to import your CSV file (check phpclasses.org... loaded with pop-up ads, but also loaded with gobs of great and nicely indexed scripts). As for removing the closed items from the table, that can be done by simply dropping all the records in the table before importing the new CSV file. A cleaner way to do this is to use a temporary table with the same schema until it can be confirmed that the import worked. Then drop all the old records and copy the new ones into the permanent table. This may be oversimplifying the problem, but it seems to address your need.
I'll look into the phpclasses.org site for the import scripts.

I was wanting to keep the "closed" records in the table for later look ups.  I was thinking about using a temporary table for a check against any existing projects.  Let me run an idea by you (or anyone else). ;)

  • Upload the new CSV to the temporary table
  • Insert any records from the temporary table to the permanent table
  • Update any records in the permanent table that are also in the temporary table
  • Update any records in the permanent table that are not in the temporary table
  • Once all updates are done, drop the temporary table

Does this list of tasks sound plausible?  Do you think there would be a need to drop the temporary table?  Or should I just empty the temporary table?

Thank you for your help.  PHP is not in my normal languages I program in.  I'm still learning it.
[*]
http://springhillalumni.org • Springhill High School Alumni Association


Post Reply