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:

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+"<br>Aproved by Admin"
How can i do that ?
Thanks in advance.

Recommended Answers

All 6 Replies

Try this :

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

Ty vm =)

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.

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 =)

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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.