Cardale Posted December 1, 2009 Share Posted December 1, 2009 I wanted to know if it is possible with only a mysql query to only update with concat if unique? Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/ Share on other sites More sharing options...
Cardale Posted December 1, 2009 Author Share Posted December 1, 2009 Anyone got an idea? Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-968872 Share on other sites More sharing options...
sasa Posted December 1, 2009 Share Posted December 1, 2009 yes Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-968958 Share on other sites More sharing options...
Cardale Posted December 1, 2009 Author Share Posted December 1, 2009 haha ok how Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969162 Share on other sites More sharing options...
Cardale Posted December 1, 2009 Author Share Posted December 1, 2009 la la la la laaaaaaaaaaaaaaa Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969238 Share on other sites More sharing options...
premiso Posted December 1, 2009 Share Posted December 1, 2009 Well if you wanted to know how, wouldn't a better question have been, "How do you preform an update statement with concat if unique?" instead of, "Can you"? Note this sticky. Anyhow, in order to help you why not give us something to work with, as I do not fully understand what you want done, perhaps some sample code you have tried or some sample data of what you want to happen to it. That will help get your topic solved a lot quicker. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969251 Share on other sites More sharing options...
Cardale Posted December 1, 2009 Author Share Posted December 1, 2009 ? something to work with? Ok...I guess didn't think it was that complicated maybe I am wrong. UPDATE users SET iplog = CONCAT(iplog, '$ip') WHERE id='$id' I need to update a users ip in my concat list and only update it if the ip isn't already in the list. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969302 Share on other sites More sharing options...
premiso Posted December 1, 2009 Share Posted December 1, 2009 How it was explained made little sense as I did not know you were working with IP's. Now the question comes into play, why are you adding multiple ips in one column? Why not create an iplog table and add them there, this would normalize the database and probably be preferred? To answer your question, however, here is the code: UPDATE users SET iplog = CONCAT(iplog, '$ip') WHERE id = '$id' AND iplog NOT LIKE '%$ip%' Should do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969308 Share on other sites More sharing options...
Cardale Posted December 1, 2009 Author Share Posted December 1, 2009 If I wanted to look and see what ips have been used by a user a ip table wouldn't be as efficient I believe. Also I haven't done this. With this method I know exactly what ips where use by said user. Now getting that information out in a reliable way will also be a new adventure for me. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969353 Share on other sites More sharing options...
premiso Posted December 1, 2009 Share Posted December 1, 2009 Well it would actually be really easy with an ip table. You setup the id column as auto_increment, a userid column and an ip column. Make the id primary key then anytime you wanna see the ip's a user has used you just do a join query. It is actually how most databases are done and is required for a 3rd normalized form database structure. But whichever way works best for you. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969356 Share on other sites More sharing options...
Cardale Posted December 1, 2009 Author Share Posted December 1, 2009 This sql query isn't working right. Any ideas? it outputs the same ip into the database. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969362 Share on other sites More sharing options...
Cardale Posted December 1, 2009 Author Share Posted December 1, 2009 I can easily do this with PHP I was just hoping for a easier MYSQL solution. Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-969368 Share on other sites More sharing options...
fenway Posted December 4, 2009 Share Posted December 4, 2009 I can easily do this with PHP I was just hoping for a easier MYSQL solution. Anyone? You've been given the easier solution -- one row per hit. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-971236 Share on other sites More sharing options...
Cardale Posted December 6, 2009 Author Share Posted December 6, 2009 I wasn't. It didn't work right; unless I did something wrong. If I am UPDATING a row and use the sql command above it still updates the query with another mysql entry of the exact same ip. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-972187 Share on other sites More sharing options...
Cardale Posted December 6, 2009 Author Share Posted December 6, 2009 I figured it out. Thank you everyone. Quote Link to comment https://forums.phpfreaks.com/topic/183560-phpmysql-concat-update-if-unuqie/#findComment-972204 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.