CodeIgniter Forums
Modifying Query Result Object - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Modifying Query Result Object (/showthread.php?tid=7665)



Modifying Query Result Object - El Forum - 04-17-2008

[eluser]rfrancis[/eluser]
OK, here is what I'm trying to do. I have a search function that involves up-to fifty (50) fields. The search results are sent to a view that outputs a table, that is a pretty basic exercise that works with no problem.

Here is where I run into trouble. I also want to export the query results to CSV, however I need to remove some of the fields from the results, and other fields I need to replace the value.

Based on the size of the query, I'd rather not run it a second time. I'd prefer to modify the result and send it on to CI's csv_from_result.

Can anybody give me a point in the right direction for modifying the query result object? Or is my best option to build my own utility for processing the results and outputting the CSV without using CI's csv_from_result?

Thanks is advance for any thoughts or ideas...

Rory


Modifying Query Result Object - El Forum - 04-17-2008

[eluser]missionsix[/eluser]
I would suggest building your CSV string while you loop through the query results. You can then modify / exclude data as needed and build both reports on one go.


Modifying Query Result Object - El Forum - 04-18-2008

[eluser]Sean Murphy[/eluser]
You should be able to loop through the result object and modify/unset fields. Then use csv_from_result.


Modifying Query Result Object - El Forum - 04-20-2008

[eluser]rfrancis[/eluser]
[quote author="Sean Murphy" date="1208578988"]You should be able to loop through the result object and modify/unset fields. Then use csv_from_result.[/quote]

That's actually what I've been trying to do. I just haven't been successful in looping through it yet. I'll be tinkering with the code today and will post what I do or don't get to work.

Thanks!


Modifying Query Result Object - El Forum - 04-24-2008

[eluser]rfrancis[/eluser]
OK, so I'm feeling really dense on this one.

How do I loop through the result object, make modifications to it and keep it intact so I can forward it on to csv_from_result?

var_dump gives me the structure, but I can't figure out how to drill through that stucture.

Code:
array(30) {
    [0]=> object(stdClass)#16 (18)
        {
            ["SubjectID"]=> string(10) "1131754225"
            ["FirstName"]=> string(0) ""
            ["LastName"]=> string(0) ""
            ["GenderID"]=> string(1) "1"
            ["EthnicID"]=> string(1) "3"
            ["Children"]=> string(1) "1"
            ["DayPhone"]=> NULL
            ["EveningPhone"]=> NULL
            ["MobilePhone"]=> NULL
            ["Email"]=> NULL
            ["DOB"]=> NULL
            ["Occupation"]=> NULL
            ["IncomeID"]=> NULL
            ["Company"]=> NULL
            ["EducationID"]=> string(1) "6"
            ["City"]=> string(8) "Hilliard"
            ["StateID"]=> string(4) "Ohio"
            ["LastStudy"]=> NULL
         }
         etc through the results.

How do I drill through the result object to the individual fields? For example I need to modify EthnicID, how do I get to that value and modify it?