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

  • SEARCH
  • Home
  • 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 7922587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:00:56+00:00 2026-06-03T17:00:56+00:00

I am really confused. I want to create a Select drop down menu using

  • 0

I am really confused. I want to create a Select drop down menu using information from an sql database. everything works out great but i have one question. how do i update the select drop down every time the user changes his selection. the question is really confusing and i dont really know how to describe it.. I set up the code in php and then put it inside my page. here is the code:

<?php
//creating a function to generate the second select menu
function createNameSelect(){
    $options = "<select id='name'>"
    $sql = "SELECT * FROM names WHERE category = 'c'";
    $result = mysql_query($sql);

    $options.="<option value='nothing'>-- select an option --</option>";

    while ($row=mysql_fetch_array($result)){
        $name=$row['name'];
        $options.="<option value='$name'>$name</option>";
    }

    $options.="</select>";

    return "$options";
}
?>



<!DOCTYPE html>
....
<select id = c>
   <option value ='1'>option 1</option>
   <option value ='2'>option 2</option>
   <option value ='3'>option 3</option>
</select>
 <?php createNameSelect(); ?>

....
</html>

now, it works perfect, however, it won’t update the select menu that follows the first one.
it would be stuck on the menu generated from the default option.
any idea what i can do to fix it? is there a js solution to it?

Thanks!

  • 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-03T17:00:58+00:00Added an answer on June 3, 2026 at 5:00 pm

    PHP is a server side script – it will be executed precisely once on the server, and the output will be sent to the client (viewer browser). So you can’t call that PHP function over and over again as the user changes the first select.

    What you need to do is make a separate PHP file that, when given a valid option for the first select, prints out code for the second select. Then you use AJAX to invoke that PHP file using the jQuery .get() function, and replace the contents of the second select with the results you get.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really confused. I want to make a Chrome Extension that can update a
I am getting really confused with this concept: If I want to implement a
i'm really confused how to name method names in Ruby classes. if i create
I want to start to do some unit testing however I am really confused
I want to create a table Person using JPA, it is a requirement that
I want to create a matrix representation for a graph algorithm using the least
I want to create a UI for my application. What really confuses me is
I'm trying to use regular expression right now and I'm really confuse. I want
I am really confused about object relationships! I have two classes Person and Address.
I'm really confused by a behaviour of LINQ I'm seeing and it's causing me

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.