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 4381428
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:38:53+00:00 2026-05-21T12:38:53+00:00

I want to do the folowing thing, here is simple select, that gets info

  • 0

I want to do the folowing thing, here is simple select, that gets info from db.I have one db that have id/city/people.SO this is like some example selects

  Select1|Select2|
    City1   |2    
    City2   |Poeple2      
    City3   |People3      
    City4   |People1        
    City5   |PopleFromFirstCity  

Here is what i want to do, when i select some city from the first select, i want in the second select that is Select2 the output to be auto changet to what i picket in the first, so if i pick City1, the second select to have PeopleFromFirstCity and People1

  • 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-05-21T12:38:53+00:00Added an answer on May 21, 2026 at 12:38 pm

    For first selection make this:

     <form>
     Select city: <select name="cities" onchange="showCity(this.value)">
     <option value="0">Chose city...</option>
     <?php          
     $sql="SELECT id,city FROM table1 ORDER BY ID DESC";      
     $result = mysql_query($sql);
     while($row = mysql_fetch_array($result))
     {
     echo"<option value=" . $row[id] . ">" . $row[city] . "</option>";
     }
     ?>
     </select></form>
    

    For output from selection2 make div:

    <div id="txtHint"></div>
    

    Now make second table table2 which contain peoples, and make .js file

    var xmlhttp;
    
    function showCity(str)
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var url="http://fullpathtoselection2file/selection2.php"; // Example: http://www.site.com/files/selection2.php
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    
    function stateChanged()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
    }
    
    function GetXmlHttpObject()
    {
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
          }
    if (window.ActiveXObject)
    {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
    }
    

    Implement to your file where is selection 1 this js file.
    And now make selection 2:

    <?php
    // Get city id
    $q=$_GET["q"];
    // Select from SQL where city = city id
    $sql="SELECT peoples,city_id FROM table2 WHERE city_id = '".$q."' order by id desc";
    
    $result = mysql_query($sql);
    
    // echo it
    while($row = mysql_fetch_array($result))
    {
    echo $row['peoples'];
    }
    

    How you have 2 tables. table1 for cities second table2 for peoples. When you update your database for example from admin panel, u need to update 2 tables. for peoples and for cities.
    For table 1 need to contain: id, city… Table 2 need to contain id,peoples, city_id.

    Code isn’t tested.

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

Sidebar

Related Questions

I have a query that looks like the following SELECT t1.Name, t2.ID, t2.name FROM
Problem I want ot write a simple 1D RTS game and have the following
I want to use a temp directory that will be unique to this build.
If all tables I want to delete from have the column gamer_id can i
Well I have a simple problem with Nokogiri. I want to make Nokogiri::HTML::Builder to
i have a web.config file that looks like this: <?xml version=1.0?> <configuration> <system.web> <compilation
I want to ran the following script on text files that are being committed:
I want to accomplish the following scenario in Drupal: You have 2 content-types. Lets
I want to compile the following line of code from http://code.google.com/p/enhsim : enh::eout <<
I have very little experience designing databases, and now I want to create a

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.