populating a combo box without using ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreenisha
    New Member
    • Aug 2008
    • 27

    populating a combo box without using ajax

    HI

    Plz tell me how to popoulate a section field in combo box when a particular department is selected.I tried it but only department is displayed the other doesnt work.Plz tell me how to write the query for this subselection.Pl z help .
    Last edited by sreenisha; Sep 19 '08, 06:39 AM. Reason: code attached wrong
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by sreenisha
    HI

    Plz tell me how to popoulate a section field in combo box when a particular department is selected.I tried it but only department is displayed the other doesnt work.Plz tell me how to write the query for this subselection.Pl z help .
    Please show the code you have to give us a better chance of being able to answer the question.

    Also in the title of this thread you say 'without using AJAX' why don't you want to use AJAX. This sort of problem is solved beautifully by AJAX.

    Cheers
    nathj

    Comment

    • sreenisha
      New Member
      • Aug 2008
      • 27

      #3
      HI
      Actually i dont know Ajax Programming.Tha ts why i specified "without using ajax.Here is my php code.

      [PHP]//To Populate The First List Box $quer2="SELECT * FROM department order by dept_name;"; $res_div=pg_que ry($quer2); //To Populate The Second List Box $cat=$HTTP_GET_ VARS['cat']; // This line is added to take care if your global variable is off if(isset($cat) and strlen($cat)> 0) { $quer="select DISTINCT sec_name from section where div_id=$cat order by dept_name);"; $res_disp=pg_qu ery($quer); } else { $quer="SELECT DISTINCT sec_name FROM section order by dept_name;"; $res_disp=pg_qu ery($quer); } //end of query for second subcategory drop down list box //*Starting of first drop downlist // echo "<tr><td>Depart ment</td>"; echo "<td><selec t name='cat'><opt ion value=''>Select department</option>"; //$numrows=pg_num rows($res_div); while($row=pg_f etch_array($res _div)) { if($row['dept_id']==@$cat) { echo "<option value=\"$row[dept_id]\">$row[dept_name]</option>"; } else{ echo "<option value=\"$row[dept_id]\">$row[dept_name]</option>"; } } echo "</select></td></tr>"; //*This will end the first drop down list //Starting of second drop downlist echo "<tr><td>Discip line</td>"; echo "<td><selec t name='subcat'>< option value=''>Select section</option>"; $numrows=pg_num rows($res_disp) ; //Till here it is working. while($row=pg_f etch_array($res _disp)) { **echo "<option value=\"$row[sec_id]\">$row[sec_name]</option>" } echo "</select></td></tr>"; //This will end the second drop down list ?> [/PHP]

      <Formated version of the above code>
      [PHP]
      <?php
      //To Populate The First List Box
      $quer2="SELECT * FROM department order by dept_name;";
      $res_div=pg_que ry($quer2);

      //To Populate The Second List Box
      $cat=$HTTP_GET_ VARS['cat'];

      // This line is added to take care if your global variable is off
      if(isset($cat) and strlen($cat)> 0) {
      $quer="select DISTINCT sec_name from section where div_id=$cat order by dept_name);";
      $res_disp=pg_qu ery($quer);
      } else {
      $quer="SELECT DISTINCT sec_name FROM section order by dept_name;";
      $res_disp=pg_qu ery($quer);
      }
      //end of query for second subcategory drop down list box

      //*Starting of first drop downlist //
      echo "<tr><td>Depart ment</td>";
      echo "<td><selec t name='cat'><opt ion value=''>Select department</option>";
      //$numrows=pg_num rows($res_div);
      while($row=pg_f etch_array($res _div)) {
      if($row['dept_id']==@$cat) {
      echo "<option value=\"$row[dept_id]\">$row[dept_name]</option>";
      } else{
      echo "<option value=\"$row[dept_id]\">$row[dept_name]</option>";
      }
      } echo "</select></td></tr>";
      //*This will end the first drop down list


      //Starting of second drop downlist
      echo "<tr><td>Discip line</td>";
      echo "<td><selec t name='subcat'>< option value=''>Select section</option>";
      $numrows=pg_num rows($res_disp) ;
      //Till here it is working.
      while($row=pg_f etch_array($res _disp)) {
      **echo "<option value=\"$row[sec_id]\">$row[sec_name]</option>";
      }
      echo "</select></td></tr>";
      //This will end the second drop down list
      ?>
      [/PHP]
      plz help
      Last edited by Atli; Sep 19 '08, 09:47 AM. Reason: Added a formated version of the code, to make it easier to read.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        How is the code not working?
        What is it doing that it shouldn't be doing?
        What is it not doing that it should be doing?

        Are you getting any errors?

        There is an obvious syntax error there on line 39. Maybe that's the problem?

        Also, the $HTTP_GET_VARS array is old and deprecated. You should be using the $_GET super-global instead.

        Comment

        • sreenisha
          New Member
          • Aug 2008
          • 27

          #5
          hi
          There is no problem in the department box.It is working.All the departments are shown properly.But in the section combo box nothing is displayed.
          pg_query not found error is coming.
          Plz tell me what i actually has to do for the subselection
          Thank u

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Wait.. It says it can't find the pg_query function?
            That would mean that your PHP installation doesn't support PostgreSQL.

            Try creating a new .php file and putting this into it:
            [code=php]
            if(!function_ex ists("pg_query" )) {
            echo "PostgreSQL NOT loaded";
            }
            else {
            echo "PostgreSQL loaded";
            }
            [/code]
            If that tells you that it's NOT loaded, you need to add PostgreSQL support before you can start using those functions.

            If you give us details on your server we could try to help with that.

            Comment

            Working...