Jump to content

replace value in a row to another row

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
jwxie518

jwxie518

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,180 posts
My friend asked me this question:

$query= mysql_query("Select * From owners");
while($row = mysql_fetch_array($query))
{
$c = $row['ownid'];
$d = $row['owners'];
$res= mysql_query("UPDATE buildings SET owner='$d' WHERE ownerid='$c'");
}

Here are the facts:
Table1: buildings		row: ownerid
Table2: Owners		row:  ownid

Now, he wants to update the value from row ownerid in Table buildings to row ownid in Table Owners.

Let say buildings row ownerid (data as follow)
id
1
2
3
4


he wants the ID to be "copied" exactly the same order and same data entirely to row ownid in Table Owners.

I have searched around and found a couple other solutions: trigger???

But I want to conserve his codes, as the logic isn't wrong I think? I am not expert so please someone guide my friend through this.

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
If your copying you need to "insert" not "update".

#3
jwxie518

jwxie518

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,180 posts
actually he led me to a wrong direction, i am not sure if it is
he confirmed that both tables have the same id (data) but in a different orders
basically they are just numbers
Let's make our life eaiser

table#1 with row#1
table#2 with row#2

he wants to put the id from table#1 row#1 in the same exact order into table#2 row#2

so whatever action is taking on table#1 row#1 (insert, update, delete,), whatever the result after it, the same result will appear on table#2 row#2

i see trigger is a good method to go but i have no experience with trigger at all