0

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.

Edited by peter_budo: K

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by jen140
0

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.

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

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

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.