Multiline Update

Reply

Join Date: Jan 2009
Posts: 106
Reputation: jen140 is an unknown quantity at this point 
Solved Threads: 5
jen140 jen140 is offline Offline
Junior Poster

Multiline Update

 
0
  #1
Sep 10th, 2009
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:
  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: varmadba is an unknown quantity at this point 
Solved Threads: 8
varmadba varmadba is offline Offline
Junior Poster in Training

Re: Multiline Update

 
0
  #2
Sep 10th, 2009
Try this :

update news set content=concat(content,' <br>Aproved by Admin');
:- Varma

We are Happy to inform launch of a new site with loads of database related information Site offers wide range of functionality Forums,Blogs,Articles,Editorials and much more
http://www.sqllibrarian.info/
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 106
Reputation: jen140 is an unknown quantity at this point 
Solved Threads: 5
jen140 jen140 is offline Offline
Junior Poster

Re: Multiline Update

 
0
  #3
Sep 10th, 2009
Ty vm =)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 3
Reputation: adamsonsk is an unknown quantity at this point 
Solved Threads: 0
adamsonsk adamsonsk is offline Offline
Newbie Poster

Re: Multiline Update

 
0
  #4
Sep 10th, 2009
Originally Posted by jen140 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 106
Reputation: jen140 is an unknown quantity at this point 
Solved Threads: 5
jen140 jen140 is offline Offline
Junior Poster

Re: Multiline Update

 
0
  #5
Sep 10th, 2009
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 =)
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 190
Reputation: mwasif is an unknown quantity at this point 
Solved Threads: 25
mwasif mwasif is offline Offline
Junior Poster

Re: Multiline Update

 
0
  #6
Sep 10th, 2009
Originally Posted by jen140 View Post
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 106
Reputation: jen140 is an unknown quantity at this point 
Solved Threads: 5
jen140 jen140 is offline Offline
Junior Poster

Re: Multiline Update

 
0
  #7
Sep 10th, 2009
Yes it worked.
And the last response was fully for adamsonsk.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC