Page 1 of 1

[SOLVED]Update 2 fields in the same query

Posted: Thu Dec 25, 2003 5:39 am
by vigge89
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

Posted: Thu Dec 25, 2003 7:07 am
by Nay

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

Posted: Thu Dec 25, 2003 7:08 am
by Weirdan
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

Posted: Thu Dec 25, 2003 11:45 am
by vigge89
thanks!

Posted: Thu Dec 25, 2003 2:41 pm
by vigge89
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.

Posted: Thu Dec 25, 2003 2:54 pm
by Weirdan
varchar and char are limited to 128 characters so text would be the best in this case.

Posted: Thu Dec 25, 2003 3:08 pm
by vigge89
ok, but what should i set the lenght to? null?

Posted: Thu Dec 25, 2003 3:14 pm
by Weirdan
you cant specify the lenght of text column, so just text:

Code: Select all

create tables sometable (somecolumn text, someothercolumn someothertype,....);

Posted: Thu Dec 25, 2003 3:18 pm
by vigge89
im doing it in PHPmyadmin, so i thought i needed to fill in all fields, but ok, i'll just leave it then, thanks!

Posted: Sat Dec 27, 2003 11:42 am
by JAM
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.

Posted: Sun Dec 28, 2003 1:37 pm
by Weirdan
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)