Jump to content

EDI X12 Data


viviosoft

Recommended Posts

Hello All,

 

I have a client that uses a data standard that is going by the way side but is still used in many data exchange solutions today.  My question for all of you is this.  Is there a PHP solution that can loop thru and get the data into a readable format?  Say like XML or dump the data into a database?

 

Thanks guys!

 

 

 

 

Link to comment
Share on other sites

Yeah that might help... here's what the data looks like:

 

REF*19**OHIO VALLEY FLOORING

PID*F*TRN***SUPERINTENDENT

PID*F*MAC***CARINDR

MEA**LN*125.0*FT

MEA**WD*12.0*FT

MEA**SW*0.500*FP

CTP**LPR*9.790**SY****ST

CTP**LPR*11.190**SY****CT

 

G43*003**INVENTORY

SLN*1**O******SK*RKDA100AA591*****ST*A100A

PID*F*73***SAGE TWEED

PID*F*35***A591

 

SLN*2**O******SK*RKDA100AA592*****ST*A100A

PID*F*73***CREAMY TOFFEE

PID*F*35***A592

 

SLN*3**O******SK*RKDA100AA593*****ST*A100A

PID*F*73***GALAXY GRAY

PID*F*35***A593

 

LIN**GS*A161*MF*ROOKWOOD CARPET*ST*A161

DTM*007*20110413

 

###############################################################

 

REF*19**OHIO VALLEY FLOORING

PID*F*TRN***ESSAY 24 X 24 TILE

PID*F*MAC***CARTILR

MEA**SU*1.000*CT

CTP**LPR*120.410**CT

G43*003**INVENTORY

 

SLN*1**O******SK*RKDA1615110*****ST*A161

PID*F*73***JAMOCA CREAM

PID*F*35***15110

 

LIN**GS*A162*MF*ROOKWOOD CARPET*ST*A162

DTM*007*20110413

 

###################################################################

 

REF*19**OHIO VALLEY FLOORING

PID*F*TRN***LAKE TAHOE 12FT

PID*F*MAC***CARINDR

MEA**LN*125.0*FT

MEA**WD*12.0*FT

MEA**SW*0.333*FP

CTP**LPR*10.990**SY****ST

CTP**LPR*10.990**SY****CT

 

G43*003**INVENTORY

SLN*1**O******SK*RKDAB408001*****ST*A08

PID*F*73***LIGHTHOUSE

PID*F*35***001

 

SLN*2**O******SK*RKDAB408002*****ST*A08

PID*F*73***COOKIE DOUGH

PID*F*35***002

 

SLN*3**O******SK*RKDAB408003*****ST*A08

PID*F*73***WOOD SAGE

PID*F*35***003

 

SLN*4**O******SK*RKDAB408004*****ST*A08

PID*F*73***CAF? LATTE

PID*F*35***004

 

LIN**GS*A10*MF*ROOKWOOD CARPET*ST*A10

DTM*007*20110413

 

Link to comment
Share on other sites

Hello all,

 

I'm not new to php but there's still a little bit of a learning curve for me.  My problem isn't simple (at least not for me).  Here's my problem and I'll do my best to example:  In the below data set I'm now able to output the data in a readable format.  However, now I need to insert the data into a database.

 

Looking at the following data set I want to loop through it and the first SLN*?**O******SK* I want only the number after that which is the product SKU number ( RKDA100AA591 ).  This will be my reference for each row inserted into the database.  Each row here is a column BUT that's only true for the several rows in the data set.  The tricky part is to find the first SLN*?**O******SK* and then append the other data to that row.  For example:

 

REF*19 (Would be a column in the database)  --- I would need OHIO VALLEY FLOORING but for each Referenced SKU #

PID*F*TRN (Would be a column in the database)  --- I would need SUPERINTENDENT but for each Referenced SKU #

PID*F*MAC (Would be a column in the database)  --- I would need CARINDR but for each Referenced SKU #

and so on...

 

So the database output would look something like:

 

SKU                          |  PRICE1          |  PRICE2    |  COLOR

---------------------------|-------------------|---------------|------------------

RKDA100AA591        |  9.790            |  11.190    |  SAGE TWEED

RKDA100AA592        |  9.790            |  11.190    |  CREAMY TOFFEE

RKDA100AA593        |  9.790            |  11.190    |  GALAXY GRAY

 

 

If you can imagine that the method would be looping though thousands of these products and building a table of data in the database.  The beginning of each loop would start with REF*19 and the end will always end with DTM*007.  I've managed to clean the data using the code below.  But I'm thinking that it's not the best solution for what I'm trying to achieve here.  I'm sure there's someone out there that is smart enough to help me find a solution for this ;)  Thanks for any help you can provide.

 

#####  BEGIN PRODUCT LOOP #####

 

REF*19**OHIO VALLEY FLOORING

PID*F*TRN***SUPERINTENDENT

PID*F*MAC***CARINDR

MEA**LN*125.0*FT

MEA**WD*12.0*FT

MEA**SW*0.500*FP

CTP**PRICE1*9.790**SY****ST

CTP**PRICE2*11.190**SY****CT

 

####### BEGIN INTERNAL LOOP #######

 

G43*003**INVENTORY

SLN*1**O******SK*RKDA100AA591*****ST*A100A

PID*F*COLOR***SAGE TWEED

PID*F*35***A591

 

SLN*2**O******SK*RKDA100AA592*****ST*A100A

PID*F*COLOR***CREAMY TOFFEE

PID*F*35***A592

 

SLN*3**O******SK*RKDA100AA593*****ST*A100A

PID*F*COLOR***GALAXY GRAY

PID*F*35***A593

 

######## END INTERNAL LOOP ########

 

LIN**GS*A161*MF*ROOKWOOD CARPET*ST*A161

DTM*007*20110413

 

####### END PRODUCT LOOP #######

 

$row = 1;
if (($handle = fopen("832x12Data.txt", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, "*")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($i=0; $i < $num; $i++) {
            echo $data[$i]. "\n";
        }
    }
    fclose($handle);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.