Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Thu Dec 25, 2003 5:39 am
How do I update 2 or more fields in one query?
i've tested this, but i can't get it to work;
Code: Select all
<?php
$sql = "UPDATE skin, email SET skin = '$skin' SET email = '$email' WHERE nick = '$usrname'";
@mysql_query($sql);
?>
Im a beginner at MySQL and i have no idea if it's possible at all
Last edited by
vigge89 on Thu Dec 25, 2003 11:45 am, edited 1 time in total.
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Thu Dec 25, 2003 7:07 am
Code: Select all
$sql = "UPDATE the_table SET name = 'nay', obbession = 'php', the_other_obbession = 'heredoc' WHERE nick = '$username'";
$result = mysql_query($sql, $connection);
Hope that helps vigge
-Nay
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Dec 25, 2003 7:08 am
MySQL manual wrote:
6.4.5 UPDATE Syntax
UPDATE [ LOW_PRIORITY ] [ IGNORE ] tbl_name
SET col_name1=expr1 [ , col_name2=expr2, ... ]
[ WHERE where_definition ]
[ LIMIT # ]
You can update several fields in one query:
Code: Select all
update sometable set somefield='this', someotherfield='that';
but you can't reference more then one table:
Code: Select all
update sometable, someothertable.... // this won't work
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Thu Dec 25, 2003 11:45 am
thanks!
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Thu Dec 25, 2003 2:41 pm
BTW, if i want to store text in a mySQL field, which fieldtype should i use?
It would be used as notes, ie; a notepad, so it should be able to contain long texts, but not in the megabyte-size.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Dec 25, 2003 2:54 pm
varchar and char are limited to 128 characters so text would be the best in this case.
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Thu Dec 25, 2003 3:08 pm
ok, but what should i set the lenght to? null?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Dec 25, 2003 3:14 pm
you cant specify the lenght of
text column, so just
text :
Code: Select all
create tables sometable (somecolumn text, someothercolumn someothertype,....);
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Thu Dec 25, 2003 3:18 pm
im doing it in PHPmyadmin, so i thought i needed to fill in all fields, but ok, i'll just leave it then, thanks!
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Sat Dec 27, 2003 11:42 am
Weirdan wrote: varchar and char are limited to 128 characters so text would be the best in this case.
Actually, char is limited to 0-255 and varchar to 1-255.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Sun Dec 28, 2003 1:37 pm
JAM wrote: Weirdan wrote: varchar and char are limited to 128 characters so text would be the best in this case.
Actually, char is limited to 0-255 and varchar to 1-255.
Mine are limited to 128 ;P (MySQL tuned by me)