Hi everyone,
I'm working on a database project where biology searchers will be able to store information on animals, from all kind of species.
This database contains a framework to store info on animals themselves but also on evaluations that they go thru.
Each evaluation has some basic info that you need to enter, but each species also have criterias that needs to be evaluated. I do this without problem with a dynamix php form. So this means I have a table for animals, evaluation, criterias, species_type and results.
Now I need to output a report, some kind of excel file, actually a CSV file. I have no problem generating the CSV file. But I have issues putting the information in the "right" way.
What I get is one row for each results of each criteria :
What I'd like to get is 1 row for each eval + all the results of the criterias evaluated on one line:
My mysql version is 4.1.22.
My mysql query is :
Select
animal.Nom_Animal As 'Animal ID',
caract.Caract As 'Criteria',
resultat.Valeur As 'Result',
evaluation.Notes As 'Notes',
status.Status As 'Current status',
type_immigrant.Type_Immigrant As 'Emigrant type',
type_animal.Type_Animal As 'Species',
sexe.Sexe As 'Gender',
status1.Status As 'Status at eval',
status1.Code As 'Status code'
From
evaluation
Inner Join resultat On resultat.ID_Evaluation = evaluation.ID_Evaluation
Inner Join caract On resultat.ID_Caract = caract.ID_Caract
Inner Join animal On evaluation.ID_Animal = animal.ID_Animal
Inner Join type_animal On type_animal.ID_Type_Animal = animal.ID_Type_Animal
Inner Join sexe On sexe.ID_Sexe = animal.ID_Sexe
Inner Join type_immigrant On type_immigrant.ID_Type_Immigrant = animal.ID_Type_Immigrant
Inner Join status On status.ID_Status = animal.ID_Status
Inner Join status status1 On status1.ID_Status = evaluation.ID_Status
Where
animal.ID_Type_Animal LIKE '".$type."' // refers to a specific animal type choosen in a previous form
AND animal.ID_Sexe LIKE '".$sexe."' // refers to a gender selection in a previous form
AND animal.ID_Status LIKE '".$status."' // refers to an animal status selected in a previous form
Order By
animal.Nom_Animal
My database tables and structure are the following (I'm showing you only the pertaining part because the rest is big.ructure.PNG[/img]
I might do a double for loop to do this in php but this will generate a lot of queries since there are 11 000 evaluations lines in the eval table and 33 000 result lines in the result table.
So there I am, I'm not asking for a complete answer. I'm a hard worker and I want to get this right. So far I've been able to work a lot of things right, but with this problem i'm wondering if my structure is just not compatible with this kind of request. I wonder if sql views could help me, but i'm not sure...
thanks in advance for all your answers!!