943,851 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1093
  • MySQL RSS
Sep 10th, 2009
0

Multiline Update

Expand Post »
Hello all.
I have a small db, that has news.
I want to update the field "content" to add the phraze "<br>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:
sql Syntax (Toggle Plain Text)
  1. INSERT INTO news VALUES (1,"admin","test1");
  2. INSERT INTO news VALUES (1,"nonadmin","test2");
i want to update all the values of the content be current content+"<br>Aproved by Admin"
How can i do that ?
Thanks in advance.
Last edited by peter_budo; Sep 13th, 2009 at 5:53 am. Reason: K
Similar Threads
Reputation Points: 11
Solved Threads: 6
Junior Poster
jen140 is offline Offline
116 posts
since Jan 2009
Sep 10th, 2009
0

Re: Multiline Update

Try this :

Quote ...
update news set content=concat(content,' <br>Aproved by Admin');
Reputation Points: 22
Solved Threads: 9
Junior Poster in Training
varmadba is offline Offline
83 posts
since Jun 2008
Sep 10th, 2009
0

Re: Multiline Update

Ty vm =)
Reputation Points: 11
Solved Threads: 6
Junior Poster
jen140 is offline Offline
116 posts
since Jan 2009
Sep 10th, 2009
0

Re: Multiline Update

Click to Expand / Collapse  Quote originally posted by jen140 ...
Hello all.

I want to update the field "content" to add the phraze "<br>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, '<br> 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
adamsonsk is offline Offline
3 posts
since Sep 2009
Sep 10th, 2009
0

Re: Multiline Update

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 =)
Reputation Points: 11
Solved Threads: 6
Junior Poster
jen140 is offline Offline
116 posts
since Jan 2009
Sep 10th, 2009
0

Re: Multiline Update

Click to Expand / Collapse  Quote originally posted by jen140 ...
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?
Reputation Points: 29
Solved Threads: 47
Posting Whiz
mwasif is offline Offline
312 posts
since Dec 2007
Sep 10th, 2009
0

Re: Multiline Update

Yes it worked.
And the last response was fully for adamsonsk.
Reputation Points: 11
Solved Threads: 6
Junior Poster
jen140 is offline Offline
116 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: MySQL Date Problem
Next Thread in MySQL Forum Timeline: lookup table





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC