techker Posted July 8, 2018 Share Posted July 8, 2018 (edited) Hey guys im updating a table with values and using Concat to add the values. $sql = "UPDATE NouvellesEchanges SET CouponsID = CONCAT(CouponsID,'".",".$Coupon."') WHERE EID = '$EID'"; now how to i get the information from the CouponID and separate them? the table holds the the user info and couponID's 125,123,1234,333,33333 i want to show the coupons and remove the (,) so i can have only 125 123..... thx im looking at split(";*",$string); or explode Edited July 8, 2018 by techker Quote Link to comment https://forums.phpfreaks.com/topic/307464-concat-to-un-concat/ Share on other sites More sharing options...
benanamen Posted July 8, 2018 Share Posted July 8, 2018 Something looks very not right here. Rather than showing us your attempted solution to your problem tell us about the real problem you're trying to solve Quote Link to comment https://forums.phpfreaks.com/topic/307464-concat-to-un-concat/#findComment-1559389 Share on other sites More sharing options...
requinix Posted July 8, 2018 Share Posted July 8, 2018 If CONCAT is the problem then not CONCATing in the first place would be the solution. Quote Link to comment https://forums.phpfreaks.com/topic/307464-concat-to-un-concat/#findComment-1559392 Share on other sites More sharing options...
techker Posted July 8, 2018 Author Share Posted July 8, 2018 im using the concat instead of making a new entry for every coupon..but if its to much trouble..il revert.lol with this it works.but just not sure what il do with it yet..lol cause i need to fetch the info of each coupon id to get the details $C=$team['CouponsID']; $New=explode(",", $C); foreach($New as $item) { $NewI=$item; } Quote Link to comment https://forums.phpfreaks.com/topic/307464-concat-to-un-concat/#findComment-1559427 Share on other sites More sharing options...
mac_gyver Posted July 8, 2018 Share Posted July 8, 2018 (edited) Quote with this it works.but just not sure what il do with it yet..lol cause i need to fetch the info of each coupon id to get the details storing each piece of data in its own row would make solving this simple. you would just JOIN the SELECT query that you are using now to get the CouponsID values with the table holding the coupon details. storing each piece of data in its own row will also simply duplicate checking (assuming you are checking now), since you can set up the EID and CouponsID columns as a composite unique index, and prevent duplicates from being inserted/updated. btw - you should not be putting data values directly into sql query statements. you should be using prepared queries, with a place-holder for each value and then supply the values when you execute the query. lol - what is the following from your query - Quote '".",". you are breaking out of the php double-quoted string, just to concatenate a comma back into the query. ? Edited July 8, 2018 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/307464-concat-to-un-concat/#findComment-1559428 Share on other sites More sharing options...
ginerjm Posted July 8, 2018 Share Posted July 8, 2018 To store data in the format you are apparently doing is not recommended. To have a proper RDBMS one has to normalize the data which does mean having a secondary table linked to your primary (assuming that there is a need for one) where a column in that table contains one element per row. Then your query produces (easily) a result that allows you to handle whatever process you need to apply to it without ever worrying about concat un explode. Quote Link to comment https://forums.phpfreaks.com/topic/307464-concat-to-un-concat/#findComment-1559446 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.