I want to stick some nested elseif statements in a function to neaten my code, but I'm having trouble getting the query result back from the function. I get the error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [...path...]. The query works fine as long as it isn't called from the function. My truncated code is:
case
...some code...
break;
default:
foreach ($group_array as $groupname) {
get_query_groups_on ($num_markers, $groupname);
while($row = mysql_fetch_array($result)) {
...code that parses query results returned from function...
}
}
function get_query_groups_on ($num_markers, $groupname) {
if ($num_markers == "markers12") {
$result = mysql_query("select ...many table columns...
from DNAresults
where fam_group = '".$groupname."'
order by fam_group") or die(mysql_error());
} elseif {
...other variations of query...
}
return $result;
}
The error occurs on the while loop. Variable $num_markers is a POST variable that determines which case to use in the switch.
I think I can pretty much stick all of the default case in the function and get it to work that way, but for future reference I'd like to know how to get a query result back from a function.