Jump to content

Concat to Un concat?


techker

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.