asmith Posted November 26, 2007 Share Posted November 26, 2007 i'm really sorry guys to ask a simple mysql question here, but really i didn't find the answer . the code is : replace into tablename (field) values ('a'); but i want to replace a record in a specific row . so i did : replace into tablename (field) values ('a') where username = 'john' ; but it give me syntax errors! :-\ kinda in a hurry Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 26, 2007 Share Posted November 26, 2007 You can do that with update too UPDATE tablename SET 'username' = 'a' WHERE 'username'='john'; Quote Link to comment Share on other sites More sharing options...
asmith Posted November 26, 2007 Author Share Posted November 26, 2007 done ! i thought update do not delete last information , just add. is there a command to write a value beside the record ? for example in a table , username = john . then i would add "1" in the right or left of john : 1john or john1 . (i know i could get john, put in a variable then add 1 to it , any sql comand instead of 3 ,4 php lines ?) Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 26, 2007 Share Posted November 26, 2007 What do you mean exactly by is there a command to write a value beside the record ? for example in a table , username = john . then i would add "1" in the right or left of john : 1john or john1 . You can write anything inside that quote instead of john WHERE 'username'='john1'; or WHERE 'username'='1john'; OR WHERE 'username'='I hate you john'; Quote Link to comment Share on other sites More sharing options...
asmith Posted November 26, 2007 Author Share Posted November 26, 2007 i meant add a "string" to a record, update delete the last record and replace that with new one , i meant the new value go beside the old one , old value "i hate you john" i add "!!!" to the field so it will be " i hate you john!!!" Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 26, 2007 Share Posted November 26, 2007 Then you should try something like this UPDATE tablename SET username=REPLACE(username,'john', 'john !!!'); it works like this update tablename set field = replace(field,'search_for_this','replace_with_this'); Quote Link to comment Share on other sites More sharing options...
asmith Posted November 26, 2007 Author Share Posted November 26, 2007 all done ! you really helped ! thanks ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.