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 Link to comment https://forums.phpfreaks.com/topic/78889-solved-replace/ 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'; Link to comment https://forums.phpfreaks.com/topic/78889-solved-replace/#findComment-399281 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 ?) Link to comment https://forums.phpfreaks.com/topic/78889-solved-replace/#findComment-399284 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'; Link to comment https://forums.phpfreaks.com/topic/78889-solved-replace/#findComment-399286 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!!!" Link to comment https://forums.phpfreaks.com/topic/78889-solved-replace/#findComment-399290 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'); Link to comment https://forums.phpfreaks.com/topic/78889-solved-replace/#findComment-399292 Share on other sites More sharing options...
asmith Posted November 26, 2007 Author Share Posted November 26, 2007 all done ! you really helped ! thanks ! Link to comment https://forums.phpfreaks.com/topic/78889-solved-replace/#findComment-399297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.