Copying rows from another table in MySQL

Discussion in 'PHP' started by Connor Beaton, Jun 25, 2009.

  1. #1
    Hey,

    I need to make a query to pull the fields id and game from table A and insert them as media_id and game_id in table B, but only if the field game is not empty. I also need to insert 'news' into the field media_type in table B.

    How can I achieve this?

    Thanks,
    Connor Beaton
     
    Connor Beaton, Jun 25, 2009 IP
  2. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this:
    $query_non_empty = "select id, game from table_one where game <> ''";
    $result_non_empty = mysql_query($query_non_empty) or die(mysql_error());
    while($non_empty_rows = mysql_fetch_array($result_non_empty)){
    	$xfer = "insert into table_two (media_id ,game_id) values ('".$non_empty_rows['id']."','".$non_empty_rows['game']."');";
    	$xfer_result = mysql_query($xfer) or die(mysql_error());
    }
    PHP:
     
    zeronese, Jun 25, 2009 IP
  3. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hasn't this already been solved elsewhere? :-/
     
    Wrighty, Jun 25, 2009 IP