ppgpilot Posted March 19, 2011 Share Posted March 19, 2011 I am trying to find a way to copy a number of records from db 3 back into db 3, only changing the date of the copied records I have a PHP script that I use to record calories. I do this by entering items eaten during the day. I enter a food item from a dropdown menu. These items are in db 4 and each has the calorie count, protein, fat etc. for that item The script places the item and data from tbl 4 into tbl 3 So I enter maybe 15 items for each day, all unique except the $day variable which is the same in all the entries (say 15 records) since all items belong to that day I find it convienient now to copy a days worth of entries (15 entries in this example) from tbl 3 back into tbl 3, except change the $day variable from yesterday to today This is so that I do not need to enter the same items again for multiple days - boring, tedious, waste of time, etc. So if I plan to eat the same items today as I did on a past day, The script asks for the original day, then the new day so far so good It then needs to copy the original days entries back into the db, only changing the date field from the old date to the new date for each of the entries I am sure this is simple, I just don't have enough experience to know how to make it happen. Someone on the sight showed me how to copy 1 record, but I need to copy multiples. So, I carry in the $original_date and the $new_date the fields for tbl 3 are as follows: day, type, history period, item, amt, calorie, fat, fat_calories, protein, carb, sugar, sodium Anyone have an answer for this one? Thanks!! David Quote Link to comment https://forums.phpfreaks.com/topic/231079-copy-several-records-into-same-db/ Share on other sites More sharing options...
The Little Guy Posted March 19, 2011 Share Posted March 19, 2011 assuming you don't have an auto increment field, or some unique field type: Insert into table_name select * from table_name where somevalue = 'something' and someothervalue = 'somethingelse' Quote Link to comment https://forums.phpfreaks.com/topic/231079-copy-several-records-into-same-db/#findComment-1189582 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.