simple adding to of fields

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

simple adding to of fields

Post by br5dy »

i've created a page that posts messages to users. however, i can't get it to post to all the users. i have a field called 'notetouser', and all i want to do is simply add on to what i already have. update just replaces it. i think i need to use the join command but i'm not familiar with it?

thanks a lot,
brady :D
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Adding some code with the story is always nice, if you would like for somebody to be able to help you.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You could try

Code: Select all

UPDATE table
SET column=CONCAT(column, ' the stuff to add')
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post by br5dy »

:D thanks tim, that worked. this is the code i have:

Code: Select all

$alright = mysql_query(&quote;UPDATE main SET notetouser=CONCAT(notetouser, '$dapost')&quote;,$nhs);
however, when i try to 'print' my code, it comes up as one line. i've tried using '\n' but it doesn't work, and i've also tried using the escape slash '\\n' but it still doesn't work. any ideas?

thanks.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Where did you "print" it? Don't forget HTML ignores newlines etc, and you probably want to use nl2br
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post by br5dy »

duh, i forgot about that. and...haha yes! that worked perfect. thanks.

basically i created a 'post message' script that added a message to all user accounts, then when a user logged in it would show that message on their account.

everything works now, thanks.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Most people end up with the following tables:

users (user_id, ....)
messages (message_id, sender_id, content)
usermessages ( message_id, reciever_id)

This way you don't need to mess with concat/substr to add/remove messages...
Post Reply