Welcome Guest, Not a member yet? Register   Sign In
MY_Xml_Writer - Easy XML writer library
#21

[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');
foreach ($correspondance_graph as $corr) {
    if ($corr == $row->fonction) {
        $xml->addNode(Projet_Graph, $row->num_fonctions);
    }
}
#22

[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 ?
#23

[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?
#24

[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.
#25

[eluser]JoostV[/eluser]
OK, so now I know what is in your table.
Code:
$equipes->id;
$equipes->fonction;
$equipes->id_etudiant;
$equipes->id_projet;
I imagine that your table equipes sets functions that ties students to projects: e.g. student 1 is a graphist for project 23, and AD for project 24, and so on.

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.
#26

[eluser]Shimura[/eluser]
This is an example of XML TEST :

Code:
<Etudiant Promotion="2010" Nb_id="224">
        <Annees>h1,h2,h3</Annees>
        <Prenom>****</Prenom>
        <Nom>****</Nom>
        <Evaluation>
            <Eval_Projet>3</Eval_Projet>
            <Eval_Technologie>3</Eval_Technologie>
            <Eval_Graphique>3</Eval_Graphique>
            <Eval_Maketing>3</Eval_Maketing>
        </Evaluation>
        <Projet>
            <Fonction_Projet>Chef de projet</Fonction_Projet>
            <Projet_Projet>1</Projet_Projet>
            <Fonction_Projet>Designer</Fonction_Projet>
            <Projet_Graph>1</Projet_Graph>
            <Fonction_Projet>Designer</Fonction_Projet>
            <Projet_Graph>1</Projet_Graph>
            <Fonction_Projet>Développeur</Fonction_Projet>
            <Projet_Tech>1</Projet_Tech>
            <Fonction_Projet>Développeur</Fonction_Projet>
            <Projet_Tech>1</Projet_Tech>
            <Fonction_Projet>Développeur</Fonction_Projet>
            <Projet_Tech>1</Projet_Tech>
            <Fonction_Projet>Développeur</Fonction_Projet>
            <Projet_Tech>1</Projet_Tech>
            <Fonction_Projet>Graphiste</Fonction_Projet>
            <Projet_Graph>1</Projet_Graph>
            <Fonction_Projet>Intégrateur</Fonction_Projet>
            <Projet_Tech>1</Projet_Tech>
            <Projet_Tech>1</Projet_Tech>
            <Fonction_Projet>Soutien</Fonction_Projet>
            <Fonction_Projet>Soutien</Fonction_Projet>
            <Fonction_Projet>Soutien</Fonction_Projet>
        </Projet>
        <Stages>
            <Stage_Poste>Développeur Flash</Stage_Poste>
            <Id_Etudiant>224</Id_Etudiant>
        </Stages>

You see the problem :

Code:
<Fonction_Projet>Designer</Fonction_Projet>
            <Projet_Graph>1</Projet_Graph>
            <Fonction_Projet>Designer</Fonction_Projet>
            <Projet_Graph>1</Projet_Graph>

And i want :
Code:
<Fonction_Projet>Designer</Fonction_Projet>
<Fonction_Projet>Designer</Fonction_Projet>
<Projet_Graph>2</Projet_Graph>

I recover on result 1 for one node. But me i want a total result for one node.
#27

[eluser]Shimura[/eluser]
And this is an example of one student only, i have about 40 students for a promotion.
#28

[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*/
$sql = 'SELECT *, COUNT(`fonction`) as num_fonctions FROM equipes GROUP BY `id_etudiant`, `fonction`';
$query = $this->db->query($sql);

/*Store in an associative array, with the student id as key*/
$student_functions = array();
if ($query->num_rows() > 0) {
    foreach ($query->result_array() as $row) {
        $student_functions[$row['id_etudiant']][] = $row;
    }
}

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*/
$xml->startBranch('projet');
foreach ($student_functions[$id_etudiant] as $function) {
    $xml->startBranch('fonction', array('id' => $function['fonction']));
    $xml->addNode('num_functions', $function['num_fonctions']);
    $xml->endBranch();
}
$xml->endBranch();

This will give you a clean piece of properly nested XML without any repetitions, like this:
Code:
<projet>
    <fonction id="Chef de projet">
        <num_functions>1</num_functions>
    </fonction>
    <fonction id="Designer">
        <num_functions>2</num_functions>
    </fonction>
</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>
    <fonction>
        <jobtitle>Chef de projet</jobtitle>
        <type>project</type>
        <num_functions>1</num_functions>
    </fonction>
    <fonction>
        <jobtitle>Designer</jobtitle>
        <type>graph</type>
        <num_functions>2</num_functions>
    </fonction>
</projet>
But that's really up to you.
#29

[eluser]Unknown[/eluser]
how i can generate it to .xml file (sory i not good english)
#30

[eluser]JoostV[/eluser]
Just grab the data and save it to a file, for instance using the file helper:

http://ellislab.com/codeigniter/user-gui...elper.html




Theme © iAndrew 2016 - Forum software by © MyBB