Hello,
I have a problem that I have been working on for about two weeks now that is making me nuts. I am trying to pull data from a couple of MySQL tables to populate three dropdowns and use the input from the user to pull reports. The first table is has only 2 columns - site_id and name. The columns in the second table that make a difference are grade, teacher_id, and site_id.
The first dropdown variable gets assigned with no problem; however the other two don't get assigned, even though the data in the dropdowns is correct. I'm sure that I'm doing someting dumb sigh. help!
CJY
PS: I'm doing the CONCAT() in the second two dropdowns to create a unique numeric value to match with the dropdown value.
Here's the code:
<?php
## Assign connection values##
$db="reading";
$tbl1="site";
$tbl2="reading";
##Create db Connection Here - (is OK)##
## dropdown One - School Select (this one works)##
get data for dropdown one
$query1 = mysql_query("SELECT site_id, name FROM $db.$tbl1 ORDER BY name");
echo "<select name = site onchange = document.selectform.submit()";
if (!isset ($site)) { echo "<option value=null selected>Choose a Site</option> ";}
loop to get values for dropdown1
while(list($site_id,$name) = mysql_fetch_row($query1))
{
echo "<option value=$site_id";
if ($site_id == $site) { echo " selected"; }
echo ">$name</option>";
}
echo "</select> ";
## dropdown Two - Grade Select (this one doesn't) ##
get data for dropdown two (based on user input for dropdown one)
$query2 =mysql_query("SELECT DISTINCT CONCAT(site_id, grade) AS 'gr_id', grade FROM $db.$tbl2 WHERE site_id = '$site' ORDER BY grade");
echo "<select grade = gr onchange = document.selectform.submit()";
if (!isset ($gr)){ echo "<option value=null selected>Choose Site First</option> ";}
loop to get values for dropdown 2
while(list($gr_id,$grade) = mysql_fetch_row($query2))
{
echo "<option value=$gr_id";
if ($gr_id == $gr) { echo " selected"; }
echo ">$grade</option>";
}
echo "</select> ";
## dropdown Three - Teacher Select (this one doesn't either) ##
get data for dropdown three (based on user input for dropdowns one and two)
$query3 =mysql_query("SELECT DISTINCT CONCAT(site_id, teacher_id) AS 'tch_id', teacher FROM $db.$tbl2 WHERE site_id = '$site' ORDER BY teacher");
echo "<select tch_id = teach onchange = document.selectform.submit()";
if (!isset ($_site)) { echo "<option value=null selected>Choose Grade First</option> ";}
loop to get values for dropdown 3
while(list($tch_id,$teacher) = mysql_fetch_row($query3))
{
echo "<option value=$tch_id";
if ($tch_id == $teach) { echo " selected"; }
echo ">$teacher</option>";
}
echo "</select> ";
?>