darylesha Posted July 27, 2007 Share Posted July 27, 2007 I am new to php coding and website design. I was wondering if anyone could help me figure something out. Okay so I have a dynamic website that prints the info in the database out with checkboxes next to it. When a user checks the boxes and press the submit button, the record should be deleted from the database and then they should be stored in another database that assigns a different primary key ( not in that order). Also I would like for the user to be redirected back to the same page and for the records that were deleted, not to show up. I'm figuring that I need to use a if...else statement as well as some type of loop. Any other help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
grimmier Posted July 27, 2007 Share Posted July 27, 2007 if you are moving data from one database or table to another one. I recommend a 3 step approach. 1: UPDATE any information you are changing, in the original database. 2: Use REPLACE INTO and copy the rows of data you need over to the new db / table. 3: once that succeeds then DELETE the rows from the original. Quote Link to comment Share on other sites More sharing options...
ignace Posted July 27, 2007 Share Posted July 27, 2007 in addition to what grimmier wrote: instead of step 3 where you would delete all rows out of a table you will probably not use anymore, use: DROP TABLE your_table this will delete the complete table Quote Link to comment Share on other sites More sharing options...
grimmier Posted July 27, 2007 Share Posted July 27, 2007 in addition to what grimmier wrote: instead of step 3 where you would delete all rows out of a table you will probably not use anymore, use: DROP TABLE your_table this will delete the complete table Yeah i didn't want to put this in there, incase it was just moving certain rows. I use the 3 step approach when moving inventory items from the main DB to the relief DB. To add to ignace some. If you are moving everything and want to keep the old table . use Empty Table. it removes the data, leaves the structure and resets the auto incriments. Quote Link to comment Share on other sites More sharing options...
ignace Posted July 27, 2007 Share Posted July 27, 2007 TRUNCATE TABLE if you want everything to be reset Quote Link to comment Share on other sites More sharing options...
darylesha Posted July 27, 2007 Author Share Posted July 27, 2007 Thanks again for your help. I am probably gonna use the DELETE because there are just specific rows that I would like to delete. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 27, 2007 Share Posted July 27, 2007 if you are moving data from one database or table to another one. I recommend a 3 step approach. 1: UPDATE any information you are changing, in the original database. 2: Use REPLACE INTO and copy the rows of data you need over to the new db / table. 3: once that succeeds then DELETE the rows from the original. REPLACE INTO would be a bad idea as the questioner stated the PKs will be different in the other table Quote Link to comment Share on other sites More sharing options...
grimmier Posted July 27, 2007 Share Posted July 27, 2007 Good catch Barand. i overlooked that part. in such a case you would need to use Insert. Quote Link to comment 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.