I am trying to fetch data from one table based on entries in a second table. The fetched data needs to be sorted after collection and before output to my html view.
Here is an example of what I am trying to do:
I have a form/table called Enter Genotypes. The table contains 12 fields that each represent a specific gene and each field has a dropdown that displays the genotypes that relate to that gene. The user selects the appropriate genotype from the dropdown. Each gene (field) can have a unique list of genotypes (example gene rs4994 has genotypes CC, TC, TT associated while rs9939609 has AA,TA,TT). A completed record in the Enter genotypes table will have one genotype entered into each specific gene field. (example: in one record the field rs4994 contains the data CC, field rs9939609 contains the data TA, and so on for ten more genes). So far so good.
I have a second table called Studies. The table contains a number of studies that pertain to each gene and genotype. Each gene/genotype combination can have multiple studies (records). (In other words, gene rs4994 with the genotype CC may have multiple studies that apply.) I need to return all of the appropriate studies for each of the 12 genes captured in the Enter Genotypes table. Still OK so far.
I have created an HTML view that reads the data for a specific record in the Enter Genotypes table and fetches the appropriate studies. I am using the HTML table class for displaying the data. The HTML view looks at each field in the Enter Genotypes table and grabs all of the studies for each gene/genotype combination from the Studies table. Everything works fine except that I would like to sort the returned studies according to at least one (probably more) field from the Studies table. At the moment everything just appears in the order the script is written. Can I somehow use the List() function here?
Current clumsy code snippet (partial) for retrieving data for two fields (two genes). The full script fetches Study data for 12 fields/genes.
<%for each rsID in Enter_Perfect_Fit_test_results [Email1 == input.email]
{
rsID9939609 = rsID.rs9939609;
rsID4994 = rsID.rs4994;
<%for each gn9939609 in Studies [(Influencing_Gene == "rs9939609" && Influencing_Genotype == rsID9939609)]
{
in9939609 = gn9939609.Influencing_Gene;
ge9939609 = gn9939609.Influencing_Genotype;
de9939609 = gn9939609.Response;
li9939609 = gn9939609.Links;
ci9939609 = gn9939609.Citations;
}%>
<%if (de9939609 != null)
{%>
<tr class=zc-viewrow>
<td><%=in9939609%></td>
<td><%=ge9939609%></td>
<td width='750'><%=de9939609%></td>
<td><%=li9939609%></td>
<td><%=ci9939609%></td>
</tr>
<%}%>
<%for each gn4994 in Studies [(Influencing_Gene == "rs4994" && Influencing_Genotype == rsID4994)]
{
in4994 = gn4994.Influencing_Gene;
ge4994 = gn4994.Influencing_Genotype;
de4994 = gn4994.Response;
li4994 = gn4994.Links;
ci4994 = gn4994.Citations;
}%>
<%if (de4994 != null)
{%>
<tr class=zc-viewrow>
<td><%=in4994%></td>
<td><%=ge4994%></td>
<td width='750'><%=de4994%></td>
<td><%=li4994%></td>
<td><%=ci4994%></td>
</tr>
<%}%>
<%}%>
Thanks for your help,
John