eco Posted October 5, 2010 Share Posted October 5, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215205-your-advice-on-designing-a-cyclic-insertion/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 5, 2010 Share Posted October 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215205-your-advice-on-designing-a-cyclic-insertion/#findComment-1119251 Share on other sites More sharing options...
JonnoTheDev Posted October 5, 2010 Share Posted October 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215205-your-advice-on-designing-a-cyclic-insertion/#findComment-1119254 Share on other sites More sharing options...
eco Posted October 5, 2010 Author Share Posted October 5, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/215205-your-advice-on-designing-a-cyclic-insertion/#findComment-1119261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.