moving entries....

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

moving entries....

Post by dethron »

Hi;

I want to move an entry from tableA to tableB.

Both tables are identical and have 20 fields.

At the moving process, i will change the value of just one field.

What is the wisest way to do this?
Can you suggest a way with procesing one query?
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Write a script to say ....

select * from tableA
while($row = mysql_fetch_array($query)) {

get variables

then do an INSERT into tableB while in the loop .. that is if the ID numbers are the same.

hope that helps some ...
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

yes this is nice, but

i just want to move just one row, so while is unnecassary,

and both tables have 20 fields. So

the get variables part is a little bit long.

The method is that, creating an insert statement using 20 variables from the first table.

Then executing the query. However this does not look well.

Yeah, it is working, but i thought there should be a better way.

Thnx for the help ;)
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Sorry, I misunderstood the question.

Is this something that you are going to do on a regular basis? or a one time thing.

You could do it through PHPMyAdmin if you have access to that and export the table (and data), take the one row of information, then add it to the new table.

That's if you don't have to do it often.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Needless to say sorry ;)

In fact, this is a one time thing.

So, it is not an essential part of the project ;) But i always want to write my codes smart enough, and just writing all fields does not seem smart.

As you point, we can take information from one table (field by field) and then, dumping them to another table. That will work :)

But in this type of soulution, you have an SQL-statement like that :

INSERT INTO tbname (field1,field2,.....,field20) VALUES (value1, value2,.....,value20)

where fields are identical at both tables, and the values mined from first table.

However, it is a little bit long statement i think. Instead,

1)getting table fields information,
2)assigning them to an array,
3)creating and sql statement using "foreach (or other loop functions)"
4)quering it to mySQL.

What say you, is it logical?

Thnx for help.
Kind Regards.
Post Reply