Could some PHP guru please help me? I am creating a dynamic dropdown
list using a code snippet(Section A) as below:
Section A:
$sql_query=mysq l_query("SELECT DISTINCT semester, year from
schoolproject_p ics ORDER BY year
DESC");
echo "<select name=\"semester \" onchange=\"GoTo ()\">";
echo "<option value=\"$semest er\">-Semester Year-</option>";
while($data = mysql_fetch_arr ay($sql_query)) {
if($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$dat a[semester]\">$data[semester]:$data[year]</option><BR>";
}
echo "<option
value=\"$data[semester]\">$data[semester]:$data[year]</option>"; }
echo "</select>";
mysql_free_resu lt($sql_query);
The 'GoTo()' Javascript re-draws the same page with the chosen values
of 'semester' and 'year' so that
the values can be recovered by $_HTTP_GET_VARS , stored in two hidden
variables and then used in
another query to create another dynamic drop-down list, as in code
snippet (Section B).
$semesternow=$H TTP_GET_VARS['semester'];
$yearnow=$HTTP_ GET_VARS['year'];
if((isset($seme sternow) and strlen($semeste rnow) 0) and
(isset($yearnow ) and strlen($yearnow ) 0)){
print("<input type=\"hidden\" ID=\"semesterch osen\"
value=\"$semest ernow\">");
print("<input type=\"hidden\" ID=\"yearchosen \"
value=\"$yearno w\">");
$sql_query2=mys ql_query("SELEC T DISTINCT school from
schoolproject_p ics
WHERE semester='$seme sternow' AND
year='$yearnow' ");
echo "<select name=\"school\" onchange=\"GoMo re()\">";
echo "<option value=\"$school \">-- School --</option>";
while(list($sch ool) = mysql_fetch_arr ay($sql_query2) ){
echo "<option value=\"$school \">$school</option>";
}
echo "</select>";
mysql_free_resu lt($sql_query2) ;
Now the question:
When the page is re-drawn, how can the values of semester and year
previously chosen, be displayed in the first drop down list. I tried to
do it using the following, but it does not do anything:
f($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$dat a[semester]\">$data[semester]:$data[year]</option><BR>";
}
Any help would be greatly appreciated. Thanks in advance for your help.