By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

populating a combo box without using ajax

P: 27
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.Plz help .
Sep 19 '08 #1
Share this Question
Share on Google+
5 Replies


nathj
Expert 100+
P: 938
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.Plz 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
Sep 19 '08 #2

P: 27
HI
Actually i dont know Ajax Programming.Thats 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_query($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_query($quer); } else { $quer="SELECT DISTINCT sec_name FROM section order by dept_name;"; $res_disp=pg_query($quer); } //end of query for second subcategory drop down list box //*Starting of first drop downlist // echo "<tr><td>Department</td>"; echo "<td><select name='cat'><option value=''>Select department</option>"; //$numrows=pg_numrows($res_div); while($row=pg_fetch_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>Discipline</td>"; echo "<td><select name='subcat'><option value=''>Select section</option>"; $numrows=pg_numrows($res_disp); //Till here it is working. while($row=pg_fetch_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_query($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_query($quer);
} else {
$quer="SELECT DISTINCT sec_name FROM section order by dept_name;";
$res_disp=pg_query($quer);
}
//end of query for second subcategory drop down list box

//*Starting of first drop downlist //
echo "<tr><td>Department</td>";
echo "<td><select name='cat'><option value=''>Select department</option>";
//$numrows=pg_numrows($res_div);
while($row=pg_fetch_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>Discipline</td>";
echo "<td><select name='subcat'><option value=''>Select section</option>";
$numrows=pg_numrows($res_disp);
//Till here it is working.
while($row=pg_fetch_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
Sep 19 '08 #3

Atli
Expert 5K+
P: 5,058
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.
Sep 19 '08 #4

P: 27
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
Sep 20 '08 #5

Atli
Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  1. if(!function_exists("pg_query")) {
  2.     echo "PostgreSQL NOT loaded";
  3. }
  4. else {
  5.     echo "PostgreSQL loaded";
  6. }
  7.  
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.
Sep 20 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.