Jump to content

Your advice on designing a cyclic insertion?


eco

Recommended Posts

Hi,

 

Sorry for the Subject.  I have no idea how to write this in one line ;)

 

I'm trying to insert data into a db.  I have to cycle through each line in an imported csv file, get prompted for a category, write the data into the db and add a row into the application showing the added data.

 

So I show a page with a form that allows to import the csv file

 

* I cycle through the file

  - In the loop (as a popup, new form,...), I show the row in the csv, give it a category and write it into the db

* Go back to the original form and write the row (with it's category) to the display.

 

How would you do this and using what technology to do it?  I'm a poor developer but eager to learn so give me a principle and I'll do my best to implement it.

 

I can't figure out how to leave the loop, say with a popup, and come back to my original page/loop and continue to the next record.

 

Let me know if this is unclear and I'll give it another shot at explaining.

 

Thank you for your help.

-eco

Link to comment
Share on other sites

Since web servers are stateless (they don't know or care anything outside of the current page being requested), you would need to remember the current line of the file being processed using a session variable (or alternately you could remove each line from the file once it is successfully processed.)

 

How many total lines will you be doing this for, because it might be better if you assigned categories to 10 or more lines at one time.

 

Are you assigning categories using a drop-down select/option list or typing them in? If you are typing them, it would be simper to just open the CSV in Excel and type them into a column that you add for that purpose.

 

Edit: You could always just insert all the lines (without a category) into the database table and then have an 'edit' page where you display all the lines that don't have a category and enter the category information on that page.

Link to comment
Share on other sites

I think I would prefer to actually import the CSV data straight into a flat MySQL table. This can be done easily enough. Then you can loop through the records and insert into your properly normalized tables. Once a record has been processed it can be removed from the import table. This way there is no need to work directly with the CSV file.

Link to comment
Share on other sites

Thank you for you speedy answer!

 

I was over simplifying the work to be done to avoid useless details to my problem.  I'm actually trying to import financial data into a DB, automatically categorise it to re-import into kmymonney2 in a QIF format.  What I needed was a prompt if the category can't be found for a specific row (based on a search field).

 

Both your answers were spot on and I think I get a better idea on how this needs to be done now.

 

Thank you both!

 

Many thanks for your help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.