Welcome Guest, Not a member yet? Register   Sign In
csv_from_result and xml_from_result (mapping field names)
#1

[eluser]mmarcus44[/eluser]
Let me start off by saying I love CI, this is the best framework out there period.

I want to know if anybody has any approaches to rename the actual field names for output use. In some cases I don't want to use the field names of the data base, and I would rather pass in a mapping array with the replacements.

Anyone got any ideas?
#2

[eluser]mihailt[/eluser]
Code:
select u_name as username from somedummytable;

?
#3

[eluser]mmarcus44[/eluser]
Well an example would be:

database fieldname = social_security

and I want the title in the csv to be "Social Security Number"

In your example I can't select social_security as "Social Securtiy Number"

It almost seems like a good way to do it is to pass in a 4th argument called $mapping where $mapping would be an array of replacements for certain field names.

We would need to process those mappings in the function as well

echo $this->dbutil->csv_from_result($query, $delimiter, $newline, $mapping);

Guys got any ideas?
#4

[eluser]troy_mccormick[/eluser]
[quote author="mmarcus44" date="1229649761"]In your example I can't select social_security as "Social Securtiy Number"[/quote]

Not true...

Code:
$sql = "SELECT social_security AS `Social Security  Number` FROM table WHERE 1 = 1";

The above works just fine in MySQL 5.0.54...
#5

[eluser]mmarcus44[/eluser]
Awesome, you are right it does work. I made an assumption that it wont work becuase i though it wouldnt like caps and spaces... sorry

thanks




Theme © iAndrew 2016 - Forum software by © MyBB