![]() |
MY_Xml_Writer - Easy XML writer library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: MY_Xml_Writer - Easy XML writer library (/showthread.php?tid=16572) |
MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]JoostV[/eluser] It might be easier if you could solve this problem in you SQL; Code: $sql = 'SELECT COUNT(function) as num_fonctions, fonction FROM tablename GROUP BY fonction'; Then all you'd have to do is create a loop like this: Code: $corr = array('Graphist', 'AD', 'Art Director'); MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]Shimura[/eluser] Same problem :/ One node for one result not a total result. I have my colums num_fonctions (1,1,1,1,1) in PHPmyAdmin and in my xml : <Projet_Graph>1</Projet_Graph> <Projet_Graph>1</Projet_Graph> How i make a total of that ? MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]JoostV[/eluser] Hi Shimura, I really need some more info. What exactly is in your table and what exactly are you trying to display? MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]Shimura[/eluser] In my table equipes, i have id, fonction(Name of job in a project), id_etudiant, id_projet. The result of SQL in PHPmyadmin is : [num_functions] [fonction] [id_etudiant] 1 Graphist 200 1 AD 139 And when i'm in the result of the foreach ($correspondance_graph as $corr) , that's recover the count yes. But with the foreach, the xml display : One result for a node, like this : <projet_graph>1</projet_graph> <projet_graph>1</projet_graph> And i'm trying to display this for one student : <projet_graph>2</projet_graph> The problems comes that when my foreach find a correspondence, he displays one node : <projet_graph>1</projet_graph> Thank you. MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]JoostV[/eluser] OK, so now I know what is in your table. Code: $equipes->id; I am still having a hard time understanding what exactly you WANT to display in the XML. Do you want to display all functions for a single student? Or all students that take part in a project? Show me an example XML, please. I cannot help you if I don't know what the problme is. MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]Shimura[/eluser] This is an example of XML TEST : Code: <Etudiant Promotion="2010" Nb_id="224"> You see the problem : Code: <Fonction_Projet>Designer</Fonction_Projet> And i want : Code: <Fonction_Projet>Designer</Fonction_Projet> I recover on result 1 for one node. But me i want a total result for one node. MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]Shimura[/eluser] And this is an example of one student only, i have about 40 students for a promotion. MY_Xml_Writer - Easy XML writer library - El Forum - 04-26-2009 [eluser]JoostV[/eluser] First off, you might want to reconsider teh XML you're creating. - all XML is lowercase - Nest your tags. - you might want to use the same tag for all functions, so <function id="graph">, instead of using a different tag for each function Anyway. First retrieve all functions for all students, and store them in an array with the student id as key Code: /*Fetch all functions for all students*/ Then, for the <Projet> branch, you create a loop for a certain student like this (let's pretend that the ID for that student is available in $id_etudiant) Code: /*Add all functions for this student*/ This will give you a clean piece of properly nested XML without any repetitions, like this: Code: <projet> I'm sure you can figure out any modifications yourself. Hope to have been of help here. EDIT: alternatively, you could also construct an XML like: Code: <projet> MY_Xml_Writer - Easy XML writer library - El Forum - 02-27-2011 [eluser]Unknown[/eluser] how i can generate it to .xml file (sory i not good english) MY_Xml_Writer - Easy XML writer library - El Forum - 02-27-2011 [eluser]JoostV[/eluser] Just grab the data and save it to a file, for instance using the file helper: http://ellislab.com/codeigniter/user-guide/helpers/file_helper.html |