If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Feb 2005
    Member #
    I need something rather unique...
    I have an older table with data like this:

    Table Name:

    Column names:


    The use of this was that the "Field" column had a set value like "price" and the "Amount" column had the price... say "1,000". The "PropertyID" is what matched up to a second table (lets call it table2) that had a matching "PropertyID" column.

    I am now trying to use just table2 and want to migrate the values from table1 to table2 all at once. I need to write an MySQL query or a PHP page that can grab the values from table1, and UPDATE table2 inserting the value of the column "Amount" in a new column called "Price" in table2, where table2.PropertyID=table1.PropertyID.

    I have tried a few things but I am missing something. Hope someone can help.


  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Member #
    As this will be a one-time operation, you won't need a join at all.
    Just run a very simple extract/update script like examplified below, and your table2 will contain all prices from table1.
    (that is if the column price already exists in table2. If not you have to add that column first)

    PHP Code:
    mysql_connect($host$user$password) or die(mysql_error());
    mysql_select_db("DB_name") or die(mysql_error());

    $sql "select PropertyID, Amount FROM table1";
    $res mysql_query($sql) or die(mysql_error());

    $row mysql_fetch_array($res))
    $sql "UPDATE table2 SET Price = ".$row[1]." WHERE PropertyID = ".$row[0];
    mysql_query($sql) or die(mysql_error());

    S. Rosland

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 10:12 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: