PLEASE HELP - Drop down list related question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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
      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
         echo "<option
value=\"$data[semester]\">$data[semester]:$data[year]</option>";      }
      echo "</select>";

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).

      if((isset($semesternow) and strlen($semesternow) > 0) and
       (isset($yearnow) and strlen($yearnow) > 0)){
       print("<input type=\"hidden\" ID=\"semesterchosen\"
       print("<input type=\"hidden\" ID=\"yearchosen\"
       $sql_query2=mysql_query("SELECT DISTINCT school from
                            WHERE semester='$semesternow' AND
       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>";

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

Any help would be greatly appreciated. Thanks in advance for your help.

Re: PLEASE HELP - Drop down list related question wrote:
Quoted text here. Click to load it

I'm not completely clear what you're trying to do.

Are you saying that GoTo() submits a new HTTP request with  
?semester=...&year=... ?

I'm also not clear what you mean to have in your <option>, but you seem  
to be saying
<option value selected =  ...
where I think you mean
<option selected value = ...

Furthermore you are setting $semesternow from the CGI variable ($_GET is  
preferred over $HTTP_GET_VARS since 4.1.0, but that's presumably not  
relevant), but seem to be comparing the value retrieved from the DB with  
$semester, not $semesternow.

Does this help?


Re: PLEASE HELP - Drop down list related question


on 09/30/2006 11:05 PM said the following:
Quoted text here. Click to load it

If I got you right, you want to display linked select inputs with
options taken from database queries results, so when on you change one
select it display another with options dependent on the selected value
of the first, right?

In that case, you may want to take a look at this forms generation class
that comes with a plug-in to do that.

Actually, it does it better as it can use AJAX to update the dependent
select input options without reloading. It supports MySQL and many other

Here is an example page of what it does. This is not the AJAX/Database
driven version. For that see other example scripts that comes with the

The class is here:


Manuel Lemos

Metastorage - Data object relational mapping layer generator

PHP Classes - Free ready to use OOP components written in PHP

Site Timeline