Web Design Forums

Database Systems Help

Discussion and help on database systems such as MySQL, MSSql, SQLite, PostgreSQL

One field equals the value of another field



Site of the Month Voting - Now Open. CAST YOUR VOTE NOW!

Reply
 
LinkBack Thread Tools
Old April 11 '09, 05:16 PM (#1)
Abstract is offline
WDF Regular
 
Abstract's Avatar
 
Join Date: August 2003
Posts: 170
Abstract
One field equals the value of another field

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...

Any help is appreciated. Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 12 '09, 09:24 AM (#2)
Shadowfiend is offline
Code beautifully and honorably
 
Shadowfiend's Avatar
 
Join Date: June 2005
Location: Atlanta, GA
Posts: 4,143
Shadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond repute
Hm. I mean, you can just do it in two steps: do a SELECT name FROM table WHERE field_id = 1, and then do an UPDATE table SET name = '<name>' WHERE field_id = 10 but put the name you got from the first query in for the <name> placeholder in the second one.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 12 '09, 11:35 AM (#3)
Abstract is offline
WDF Regular
 
Abstract's Avatar
 
Join Date: August 2003
Posts: 170
Abstract
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 12 '09, 11:41 PM (#4)
Shadowfiend is offline
Code beautifully and honorably
 
Shadowfiend's Avatar
 
Join Date: June 2005
Location: Atlanta, GA
Posts: 4,143
Shadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond repute
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 13 '09, 12:16 PM (#5)
Abstract is offline
WDF Regular
 
Abstract's Avatar
 
Join Date: August 2003
Posts: 170
Abstract
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 14 '09, 12:17 AM (#6)
Abstract is offline
WDF Regular
 
Abstract's Avatar
 
Join Date: August 2003
Posts: 170
Abstract
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 14 '09, 01:37 AM (#7)
Shadowfiend is offline
Code beautifully and honorably
 
Shadowfiend's Avatar
 
Join Date: June 2005
Location: Atlanta, GA
Posts: 4,143
Shadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond reputeShadowfiend has a reputation beyond repute
Well you probably shouldn't be quoting the 10. Other than that, make sure you run mysql_query with the second SQL statement.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 14 '09, 07:27 PM (#8)
Abstract is offline
WDF Regular
 
Abstract's Avatar
 
Join Date: August 2003
Posts: 170
Abstract
Gotcha. Will do. Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 19 '09, 08:55 AM (#9)
darknailblue is offline
WDF Regular
 
darknailblue's Avatar
 
Join Date: August 2006
Posts: 131
darknailblue is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » Database Systems Help

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Fixed Amount Field to a Variable Amount Field Abstract PHP 32 April 3 '09 04:10 PM
Saving information in one field and inserting it on another field on new page? chrisjum Javascript, AJAX, and JSON 2 July 19 '07 05:37 PM
Need To Populate Field Upon Tab deadintuit General Web Design Discussion 1 June 23 '05 02:50 PM
How to imput empty field into a database using ASP lmarshall Other Languages 10 April 4 '03 02:23 PM
Updating field in BeforeUpdate mattalexx Other Languages 4 April 10 '02 09:34 PM

 
User Infomation
Your Avatar

Site Of The Month
Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 01:52 PM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164