copying DB data into same DB

I used to code a long time ago - PHP5.

It is slowly coming back to me but not fast enough…

I need to copy data from a mysql data base and put it back in unchanged with another date reference.

This is a calorie recorder that tracks daily calories - food type, calories, protein, carbs, etc.

I simply want to take each entry in that day, then copy it exactly except chenaging the date recerence.

If I could say "copy all entires where date = (date) into DB with new date (date), that would do it.

The only thing I can think to do is pull each item out and place it back into the DB with a while statement.

There has to be an easier way…

If that is my only option, I need to figure out how to create a while statement to handle an array to do the job.

Any thoughts?

Thanks for the help!!

David

The easiest way I found to do this is to make a temporary table identical to the one you have.

For example:

<?php mysql_connect(,,) or die(); mysql_select_db("db") or die(); $query1 = mysql_query("CREATE TABLE temp ( Column1 VARCHAR(1), Column2 VARCHAR(1))"); $query2 = mysql_query("INSERT INTO temp (Column1, Column2) SELECT Column1,Column2 FROM db.main_db WHERE Column1 = 'A'"); $query3 = mysql_query("UPDATE temp SET Column1 = 'Z'"); $query4 = mysql_query("INSERT INTO main_db(Column1,Column2) SELECT Column1,Column2 FROM db.temp"); $query5 = mysql_query("DROP TABLE temp"); That should do it :D
Sponsor our Newsletter | Privacy Policy | Terms of Service