Matpatnik Posted November 15, 2007 Share Posted November 15, 2007 Hi guys, Is there a way to update a column in my row without selecting the information?What I mean by that is I have this row: +-----------+----------------+| r_name | r_comment |+-----------+----------------+| name | comment |+-----------+----------------+ and I want add more information to it like this +------------------------+-------------------------+| r_name | r_comment |+------------------------+-------------------------+| name and last name | comment and reply |+------------------------+-------------------------+ I don't want to change the name of the column just the information inside of the rowDo I absolutely need to select my information before of is there a way to do it just with an update? Link to comment Share on other sites More sharing options...
Ingolme Posted November 15, 2007 Share Posted November 15, 2007 You have to take the data from the column, save it in a variable and then update the column after with the new data added to it, there's no other way to do it. Link to comment Share on other sites More sharing options...
Matpatnik Posted November 15, 2007 Author Share Posted November 15, 2007 Sorry I didn't explain myself correctlyhere what I'm trying to do: ###----- START inserting message tbl -----### $db2 = new MySqlDB; $db2->connect('localhost', 'root', 'pass'); $db2->select_db('db2'); $result = $db2->query("UPDATE message SET message_desc = '". $comment ."' message_enddate = '". $endcookie ."' message_lastmod = '". time() ."') WHERE message_username = '". $user_logged ."'"); $db2 = $db2->close(); //------------- END inserting message tbl --------------> I don't know what is inside the column message_desc and I want add $comment after it.I know with number I ca do something like this: message_desc =+ '". $comment ."' (I don't remember the exact syntax) but is there something similar to that or I have to select the column and add it manually to $comment? Link to comment Share on other sites More sharing options...
Ingolme Posted November 15, 2007 Share Posted November 15, 2007 I don't think there's an operator in SQL that can do that. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 15, 2007 Share Posted November 15, 2007 MySQL has a string concatenation function you can use. $result = $db2->query("UPDATE message SET message_desc = CONCAT(message_desc, '". $comment ."'), message_enddate = '". $endcookie ."', message_lastmod = '". time() ."' WHERE message_username = '". $user_logged ."'"); http://dev.mysql.com/doc/refman/5.0/en/str...function_concatFor T-SQL in MSSQL Server you can use the plus operator for concatenation. Link to comment Share on other sites More sharing options...
Matpatnik Posted November 15, 2007 Author Share Posted November 15, 2007 Awesome, Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.