954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Multiline Update

Hello all.
I have a small db, that has news.
I want to update the field "content" to add the phraze "
Aproved by Admin" for every row in the database.
A better explanation, i have table news, with 1 table that is defined : create table news (id int, creator char(10), content char(255));
and for example i have 2 rows:

insert into news values (1,"admin","test1");
insert into news values (1,"nonadmin","test2");

i want to update all the values of the content be current content+"
Aproved by Admin"
How can i do that ?
Thanks in advance.

jen140
Junior Poster
117 posts since Jan 2009
Reputation Points: 11
Solved Threads: 6
 

Try this :

update news set content=concat(content,'
Aproved by Admin');
varmadba
Junior Poster in Training
83 posts since Jun 2008
Reputation Points: 22
Solved Threads: 9
 

Ty vm =)

jen140
Junior Poster
117 posts since Jan 2009
Reputation Points: 11
Solved Threads: 6
 

Hello all.

I want to update the field "content" to add the phraze "
Aproved by Admin" for every row in the database. How can i do that ? Thanks in advance.

You can run an UPDATE query that updates a field relative to itself, as an example "UPDATE tbl SET tblfield = tblfield + 1" With no qualifiers, this will make every value for tblfield in that table 1 larger than it was before.

You don't say what database you're using, but you would want string concatenate functions. Assuming MySQL your query would be:

UPDATE news SET content = concat(content, '
Approved by Admin'

And that's it. Keep in mind that with no qualifiers (i.e. "WHERE category = 'approved'" or whatever) it will update *all* fields. If that's what you want, you're done.

This is my first post here. If I get formatting wrong I apologize.

adamsonsk
Newbie Poster
3 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Thanks for your response ,but i am using mysql ,as shown in the middle :
DaniWeb Community > Web Development > Databases > MySQL
And wellcome to the board =)

jen140
Junior Poster
117 posts since Jan 2009
Reputation Points: 11
Solved Threads: 6
 
Thanks for your response ,but i am using mysql ,as shown in the middle : DaniWeb Community > Web Development > Databases > MySQL And wellcome to the board =)


The above queries are for MySQL. Did you try it?

mwasif
Posting Whiz
315 posts since Dec 2007
Reputation Points: 29
Solved Threads: 48
 

Yes it worked.
And the last response was fully for adamsonsk.

jen140
Junior Poster
117 posts since Jan 2009
Reputation Points: 11
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You