Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:21:22+00:00 2026-06-02T23:21:22+00:00

I was trying out this code for getting a dropdown list populated by a

  • 0

I was trying out this code for getting a dropdown list populated by a MySQL database and if a certain category is selected another dropdown pops up.I thought this code was correct and I guess not. The first dropdown doesn’t even populate from the database it just ends up being blank,=. I’ve been tinkering with it for quite awhile with no success.

Here is what I’m trying to replicate … http://www.blueicestudios.com/chained-select-boxes-using-php-mysql-ajax/

Here is what there is so far.

The Main Form :

<?php include ('connect.php'); ?>
<?php include('func.php'); ?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"><!--mce:0--></script>

<script type="text/javascript">
$(document).ready(function() {
    $('#wait_1').hide();
    $('#drop_1').change(function(){
      $('#wait_1').show();
      $('#result_1').hide();
      $.get("func.php", {
        func: "drop_1",
        drop_var: $('#drop_1').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
        return false;
    });
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>

<form action="" method="post">

<select id="drop_1" name="drop_1">
<option disabled="disabled" selected="selected"> Select Main Category</option>
</select>
<span id="wait_1" style="display: none;">
<img src="ajax-loader.gif" alt="Please Wait">
</span>
<span id="result_1" style="display: none;"></span>
</form>

Here is the func.php file:

<?php 

function getTierOne()
{
    require_once('connect.php');
    $result = mysql_query("SELECT category FROM subcats")
    or die(mysql_error());
    while($tier = mysql_fetch_array( $result ))
    {
        $catitle = $tier['category'];
    echo "<option> $catitle </option>" ;
    }   
    mysql_close();
    }   

    if(isset($_GET['func'])&& $_GET['func'] == 'drop_1') {  
        drop_1($_GET['drop_var']);
        }
        function drop_1($drop_var)
        {
        require_once('connect.php');
        $result = mysql_query("SELECT * FROM subcats WHERE category='$drop_var'")
        or die(mysql_error());

        echo '
        <select id="subcat" name="subcat">
        <option disabled="disabled" selected="selected" value=" ">Choose one</option>
        <option value="'.$drop_2['subcat'].'">'.$drop_2['subcat'].'</option>
        </select>
        ';
        mysql_close();

        echo '
        <input name="submit" type="submit" value="Submit">';
        }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:21:25+00:00Added an answer on June 2, 2026 at 11:21 pm

    If anyone wants to know the answer I figured it out.

    Change This.

    {
            $catitle = $tier['category'];
        echo "<option> $catitle </option>" ;
        } 
    

    To this

     while($tier = mysql_fetch_array( $catresult )) 
    
            {
               echo '<option value="'.$tier['category'].'">'.$tier['category'].'</option>';
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting really tired of trying to figure out why this code works in
Boost Network I am trying out this code in a small console app on
Trying to figure out this pseudo code. The following is assumed.... I can only
I am trying to figure out why I get this error. My code is
i m new to iphone ... trying this code but getting some error help
Hey all i have been trying to figure out why i am getting this
So I'm trying out this new TDD thing (about time haha). Anyways I have
Hi iam new to c++ and iam trying out this vector program and i
I am trying out GWT in this 'configuration': 1) I have written a server
Question: I'm trying out to convert this here: http://support.microsoft.com/kb/828736 to VB.net I got it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.