Page 1 of 1
simple adding to of fields
Posted: Sat Jul 23, 2005 2:55 pm
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

Posted: Sat Jul 23, 2005 4:06 pm
by ol4pr0
Adding some code with the story is always nice, if you would like for somebody to be able to help you.
Posted: Sat Jul 23, 2005 7:35 pm
by timvw
You could try
Code: Select all
UPDATE table
SET column=CONCAT(column, ' the stuff to add')
Posted: Mon Jul 25, 2005 10:46 am
by br5dy

thanks tim, that worked. this is the code i have:
Code: Select all
$alright = mysql_query("e;UPDATE main SET notetouser=CONCAT(notetouser, '$dapost')"e;,$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.
Posted: Mon Jul 25, 2005 11:24 am
by timvw
Where did you "print" it? Don't forget HTML ignores newlines etc, and you probably want to use
nl2br
Posted: Mon Jul 25, 2005 11:48 am
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.
Posted: Mon Jul 25, 2005 12:27 pm
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...