Register

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 9 of 9
  1. #1
    Senior Member
    Join Date
    Aug 2003
    Posts
    194
    Member #
    2782
    Man I hope I didn't open up a can of worms with this one. I am hoping it is simple.... How do I query a database for a value and input that value into another field?

    For instance, let's say I have a person filling out a form. Their name (field_id=1), will populate their name somewhere else (field_id=10). How do I do this? I am trying to research the issue, but being that MySQL is not my expertise, I might not be using the proper words in my search... :ermm:

    Any help is appreciated. Thanks.

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Hm. I mean, you can just do it in two steps: do a [minicode]SELECT name FROM table WHERE field_id = 1[/minicode], and then do an [minicode]UPDATE table SET name = '<name>' WHERE field_id = 10[/minicode] but put the name you got from the first query in for the [minicode]<name>[/minicode] placeholder in the second one.

  4. #3
    Senior Member
    Join Date
    Aug 2003
    Posts
    194
    Member #
    2782
    When you refer to '<name>' is this the field name or is this the value? There is a whole bunch of entries already for field_id=1. So I want it to automatically populate field=10.

    Basically, I have 2 separate database tables. I want 'field_id=1' to automatically populate 'field_id=10'. Data is stored in one table from people filling out a form (this is where field_id=1 is located). Managers will access data in the other table that dynamically pulls in the name (field_id=10).

    I hope that clarifies it better. Since this is the case, would what you mentioned above be the code I am looking for?

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    I'm still not 100% clear on it. Give us a specific example with rows from each table (you can make up the columns/data, obviously) and that should help us understand.

  6. #5
    Senior Member
    Join Date
    Aug 2003
    Posts
    194
    Member #
    2782
    Sorry for the lack of clarity; I am hoping that I can simplify my explanation here:

    A person fills out a form that includes their 'name'.
    This information will be stored in a database table.
    I want that 'name' to also populate another database table, in which managers access.

  7. #6
    Senior Member
    Join Date
    Aug 2003
    Posts
    194
    Member #
    2782
    here is my stab at it:

    Code:
    $sql = "SELECT * FROM table_1 WHERE field_id=1";
    $result = mysql_query($sql);
    
    while($row = mysql_fetch_array($result))
    {
    echo $row['value'];
    }
    
    $sql = "INSERT INTO table_2 (value, field_id) VALUES ('$result', '10')";
    I got it to successfully query the database, but now I need it to populate table_2 with the field_id column to be '10' and the value column to equal the query from table_1. There is something I got wrong here. HELP!

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well you probably shouldn't be quoting the 10. Other than that, make sure you run mysql_query with the second SQL statement.

  9. #8
    Senior Member
    Join Date
    Aug 2003
    Posts
    194
    Member #
    2782
    Gotcha. Will do. Thanks!

  10. #9
    Senior Member
    Join Date
    Aug 2006
    Posts
    131
    Member #
    13656
    Why bother at all having 2 queries? Why not just add some kind of status field to you table? This way you can have 1 table avoid duplicates, and query the DB using something like a WHERE status = 2 or whatever. Then you can accomplish things like this...

    Status Codes

    1 = Regular User
    2 = User w/ Management Privileges
    3 = Unactive User

    etc. etc. etc.
    Christopher Carvache
    Web Developer / SEO
    Northeast Web Design
    +1.860.906.7802


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
  •  

Search tags for this page

access field equal to another field
,

access one field equal another

,

access query if one value equals another

,

convert access query field equal to another field

,
field calculator how to make one field equal another
,

get one field equal to another field in access

,

how to make one field equal another in access

,

make one field equal another access

,

make one field equal another in access

,
sql table query where one field equals another
Click on a term to search for related topics.
All times are GMT -6. The time now is 10:45 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com