Jump to content

1 row for each eval, but all the results in one line?


ezekielnin

Recommended Posts

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 : listing1.PNGwhat%20i%20get.png

 

What I'd like to get is 1 row for each eval + all the results of the criterias evaluated  on one line: what%20i%20want.png

 

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!!  :P

Link to comment
Share on other sites

@barand : What I want is almost exactly what group_concat does, but I would like each value in a different column. Is it possible?

 

@xyph : I'll try to build a proper sql, some of the data I got is confidential.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.