Replacing mysql values

Discussion in 'PHP' started by SA101, Jul 9, 2009.

  1. #1
    So I am trying to update a table from a MYSQL database with values from another table. I want to replace the values for each row of Columns A and B in table 1 with the values for each row of Columns C and D in table 2.

    How do I do this?
     
    SA101, Jul 9, 2009 IP
  2. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #2
    Is there a condition on how to replace the values? I mean which values from which row in table 1 replaces rows in table 2?
     
    samyak, Jul 9, 2009 IP
  3. SA101

    SA101 Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Values from Column A that are the same as values from Column C.
     
    SA101, Jul 9, 2009 IP
  4. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #4
    $query= mysql_query("Select * From table2");
    while($row = mysql_fetch_array($query))
    {
       $c = $row['C'];
       $d = $row['D'];
       $res= mysql_query("UPDATE table1 SET B='$d' WHERE C='$c'");
    }
    PHP:
     
    samyak, Jul 9, 2009 IP