Jump to content

Adding information into a column in mysql db


Matpatnik

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...