View Single Post
Old 02-10-2005, 06:55 PM  
Myst
Confirmed User
 
Join Date: Feb 2004
Location: Alberta, Canada
Posts: 4,708
Need some simple mysql help

Alright
I have some chatbots, and id like to save conversations for each user that my bots talk to

What would be the best way of doing this? My table has 2 columns, 'user' and 'chattext'. For every message received, what would be the best way of updaitng the table? Should i go <Select chattext from myTable where user = 'some_user'>.. If theres no results, then add the user.. if there is, then do <update mytable set chattext = mysql_result(chattext) & 'new text' where user='some_user'>??

it seems wrong cause im searching for user='some_user' two times.. once to retrieve chattext (if there is any - i do this to 1) check if the user exists in the table and 2)to store chattext for later when im updating the table). and the other to update the table where user='some_user'.

Can this be done in a better way? heres what im thinking - pseudo mysql code
"update mytable append(new_chat_text) to chattext where user='some_user'.... on error insert into table mytable(user,chattext) values some_user, new_chat_text"

but i dont know enough sql to do this right

any suggestions?
__________________
ICQ: 298-523-037
Myst is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote