techker Posted July 8, 2018 Share Posted July 8, 2018 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 Link to comment 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 Link to comment 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. Link to comment 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; } Link to comment Share on other sites More sharing options...
mac_gyver Posted July 8, 2018 Share Posted July 8, 2018 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. ? Link to comment 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.