![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
DBs in PHP
Okay, I'm not very good with databases in php (this is my first php serious application thing). if i have this:
[PHP]$sqlstring = mysql_query("SELECT * FROM someRandomTable WHERE id=1");[/PHP] obviously we're assuming there's only one entry where the id is 1. my question is, how can i then do something like assign, say, $someOtherColumnValue (or whatever var) to a different column's value in the row where the id is 1?
__________________
Children in the dark cause accidents, and accidents in the dark cause children. http://www.ronincoders.org |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
You use an update SQL query...
UPDATE tablename SET columnname = 'blah' WHERE id = '1';
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
then how would i assign the value of a column in that row to a variable?
__________________
Children in the dark cause accidents, and accidents in the dark cause children. http://www.ronincoders.org |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
you could use a loop to go through each result and return just the value you want
[PHP] $res = mysql_query("SELECT * FROM someRandomTable WHERE id=1",); while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $VAR_NAME_HERE = $row['ROW_NAME_HERE']; $VAR2_NAME_HERE = $row['ROW2_NAME_HERE']; $VAR3_NAME_HERE = $row['ROW3_NAME_HERE']; }[/PHP] how it helps magic e |
|
|
|
|
|
#5 |
|
Professional Programmer
|
for help on sql and php check out www.spoono.com/php
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Aug 2005
Location: Wilsonville, Oregon
Posts: 3
Rep Power: 0
![]() |
I dont want to sound like a jerk, but this is pretty basic, and the only reason I say that is because I think you'd benefit by going through the basic php/mysql tutorials available on the web before getting started. I think this is what you are looking for, is an update query, with variables inserted into it:
[php] $sql = "UPDATE `users` SET `name` = '$name', `email` = '$email' WHERE `id` = $id LIMIT 1"; [/php] This will update your tables with the values provided in the variable. The clause "LIMIT 1" is not even neccessary, but I use it as a safety precaution, just to keep it from updating multiple rows in some freak instance. Edit: Spoono does have a good tutorial here that will get you rolling in the right direction. Last edited by jcmnetmedia; Aug 4th, 2005 at 1:12 AM. |
|
|
|
|
|
#7 |
|
Professional Programmer
|
Also, get a good SQL book and learn how to use it. Once you get the SQL command line, the php stuff makes alot more sense
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|