|
Posted by cpptutor2000@yahoo.com on 10/01/06 02:05
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=mysql_query("SELECT DISTINCT semester, year from
schoolproject_pics ORDER BY year
DESC");
echo "<select name=\"semester\" onchange=\"GoTo()\">";
echo "<option value=\"$semester\">-Semester Year-</option>";
while($data = mysql_fetch_array($sql_query)){
if($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$data[semester]\">$data[semester]:$data[year]</option><BR>";
}
echo "<option
value=\"$data[semester]\">$data[semester]:$data[year]</option>"; }
echo "</select>";
mysql_free_result($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=$HTTP_GET_VARS['semester'];
$yearnow=$HTTP_GET_VARS['year'];
if((isset($semesternow) and strlen($semesternow) > 0) and
(isset($yearnow) and strlen($yearnow) > 0)){
print("<input type=\"hidden\" ID=\"semesterchosen\"
value=\"$semesternow\">");
print("<input type=\"hidden\" ID=\"yearchosen\"
value=\"$yearnow\">");
$sql_query2=mysql_query("SELECT DISTINCT school from
schoolproject_pics
WHERE semester='$semesternow' AND
year='$yearnow'");
echo "<select name=\"school\" onchange=\"GoMore()\">";
echo "<option value=\"$school\">-- School --</option>";
while(list($school) = mysql_fetch_array($sql_query2)){
echo "<option value=\"$school\">$school</option>";
}
echo "</select>";
mysql_free_result($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=\"$data[semester]\">$data[semester]:$data[year]</option><BR>";
}
Any help would be greatly appreciated. Thanks in advance for your help.
Navigation:
[Reply to this message]
|