I have two tables, marker_names and DNAresults. The first table stores in one column, marker, most of the column names from DNAresults.
For each column name from DNAresults I want to query the values stored excluding any 0 values.
So, in order to keep the overall sql queries small I query marker_names to get the column names from DNAresults and then perform a calculation on the results (this calc is not shown below which has nothing to do with the immediate problem).
My code at the moment is:
DNA_connect();
$marker_result = mysql_query("select marker from marker_names") or die(mysql_error());
while ($row = mysql_fetch_array($marker_result)) {
$DYSvalues = mysql_query("select '".$row['marker']."'
from DNAresults
where '".$row['marker']."' <> '0'") or die(mysql_error());
while ($row2 = mysql_fetch_array($DYSvalues)) {
echo $row2[0]."<br />";
}
}
I think the problem may lie with how I reference the mysql variables in the second query, but I've tried every way of referencing it that I can think of.
Instead of returning the values stored (in row 0) in DNAresults the echo statement in the second query outputs the column name 9 times (I'm using 9 rows to test so at least that makes sense).
If I change '".$row['marker']."' to the actual name of one of the columns in DNAresults then the output is in fact what it is supposed to be. Is there a different way I need to call the first query?
A second question would be how do I reference the output of each row from the second query in the second query so it outputs everything and not just row 0? Maybe a foreach would be the way to go?
TIA