Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 27th, 2005, 8:19 PM   #1
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
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
Intimidat0r is offline   Reply With Quote
Old Jul 27th, 2005, 9:12 PM   #2
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
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
skuinders is offline   Reply With Quote
Old Jul 28th, 2005, 7:03 PM   #3
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
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
Intimidat0r is offline   Reply With Quote
Old Jul 30th, 2005, 2:27 PM   #4
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
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
magic_e is offline   Reply With Quote
Old Aug 3rd, 2005, 1:31 PM   #5
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
for help on sql and php check out www.spoono.com/php
Lich is offline   Reply With Quote
Old Aug 4th, 2005, 12:55 AM   #6
jcmnetmedia
Newbie
 
jcmnetmedia's Avatar
 
Join Date: Aug 2005
Location: Wilsonville, Oregon
Posts: 3
Rep Power: 0 jcmnetmedia is on a distinguished road
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.
__________________
Jeremy Morgan,
Check out my SEO Blog.
Simplicity is the ultimate sophistication!

Last edited by jcmnetmedia; Aug 4th, 2005 at 1:12 AM.
jcmnetmedia is offline   Reply With Quote
Old Aug 5th, 2005, 11:04 PM   #7
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
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
Lich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC