AbeMeister
MIS
I have two tables. The first table has the data I want to output. The second table has the formatting information for the first table.
To give an example of what it looks like.
[tt]
First Table (Table_Data):
FIELD_1 | FIELD_2 | FIELD_3 | FIELD_4
--------------------------------------
DATA_A1 | DATA_A2 | DATA_A3 | DATA_A4
DATA_B1 | DATA_B2 | DATA_B3 | DATA_B4
DATA_C1 | DATA_C2 | DATA_C3 | DATA_C4
Second Table (Table_FormatData):
ORDERFIELD | FIELDNAME | FIELDWIDTH
-----------------------------------
1 | FIELD_2 | 10
2 | FIELD_4 | 10
3 | FIELD_1 | 10
My final output I want to be in a text file with this content:
123456789012345678901234567890 <- This Line For Visual Purpose
---------output.txt-----------
DATA_A2 DATA_A4 DATA_A1
DATA_B2 DATA_B4 DATA_B1
DATA_C2 DATA_C4 DATA_C1
[/tt]
Now I have done this already using alot of sweat and coding imagination in ColdFusion with the following route.
1. Query the Data Table for all the Data Information.
2. Query the Format Table for the Formatting Information.
3. Create a List of FieldNames (comma dilimited).
4. I would then LOOP through each record from the Data Table.
5. Inside the 1st loop, I would loop through the FieldName List (which is in proper order because I sorted my query by OrderField) and query the Format Table AGAIN to now get the fixed width size of the data I am pulling.
Note the tricky part is, I have to evaluate the fieldname FIRST before I can change the size of the data. In ColdFusion, there is an "Evaluate()" function that will force evaluation of a formula first...before processing anything else. This means, I can transform a formula into a Variable name if I wanted to. Then output that variable.
I don't know how to do this in PHP. And maybe I should have just asked that simple question, but I felt that I should explain what I was doing so I can illustrate the full picture and possibly get advice.
I was looking into arrays in PHP. This is something that I might consider using. (Populating an array, then outputting it into a textfile in the format I liked). Unfortunately, the concept of an array is both simple and confusing to me. Simple in that I can see how you populate it. Difficult in that I don't know how to properly use one to output and do what I want with it. Either way, I still don't see how i'm going to get away from having to evaluate my column list as variables so I can use them as such.
If this all sounds confusing, please feel free to smack me.
If you know of any functions I should try to accomplish my feat, I would much appreciate it. Thank you very much for your time.
To give an example of what it looks like.
[tt]
First Table (Table_Data):
FIELD_1 | FIELD_2 | FIELD_3 | FIELD_4
--------------------------------------
DATA_A1 | DATA_A2 | DATA_A3 | DATA_A4
DATA_B1 | DATA_B2 | DATA_B3 | DATA_B4
DATA_C1 | DATA_C2 | DATA_C3 | DATA_C4
Second Table (Table_FormatData):
ORDERFIELD | FIELDNAME | FIELDWIDTH
-----------------------------------
1 | FIELD_2 | 10
2 | FIELD_4 | 10
3 | FIELD_1 | 10
My final output I want to be in a text file with this content:
123456789012345678901234567890 <- This Line For Visual Purpose
---------output.txt-----------
DATA_A2 DATA_A4 DATA_A1
DATA_B2 DATA_B4 DATA_B1
DATA_C2 DATA_C4 DATA_C1
[/tt]
Now I have done this already using alot of sweat and coding imagination in ColdFusion with the following route.
1. Query the Data Table for all the Data Information.
2. Query the Format Table for the Formatting Information.
3. Create a List of FieldNames (comma dilimited).
4. I would then LOOP through each record from the Data Table.
5. Inside the 1st loop, I would loop through the FieldName List (which is in proper order because I sorted my query by OrderField) and query the Format Table AGAIN to now get the fixed width size of the data I am pulling.
Note the tricky part is, I have to evaluate the fieldname FIRST before I can change the size of the data. In ColdFusion, there is an "Evaluate()" function that will force evaluation of a formula first...before processing anything else. This means, I can transform a formula into a Variable name if I wanted to. Then output that variable.
I don't know how to do this in PHP. And maybe I should have just asked that simple question, but I felt that I should explain what I was doing so I can illustrate the full picture and possibly get advice.
I was looking into arrays in PHP. This is something that I might consider using. (Populating an array, then outputting it into a textfile in the format I liked). Unfortunately, the concept of an array is both simple and confusing to me. Simple in that I can see how you populate it. Difficult in that I don't know how to properly use one to output and do what I want with it. Either way, I still don't see how i'm going to get away from having to evaluate my column list as variables so I can use them as such.
If this all sounds confusing, please feel free to smack me.
If you know of any functions I should try to accomplish my feat, I would much appreciate it. Thank you very much for your time.