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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:44:50+00:00 2026-06-13T06:44:50+00:00

Have been looking around for a solution to this and have found some help

  • 0

Have been looking around for a solution to this and have found some help on stack overflow but in most cases the examples I have found are not using arrays formed from a database query. Here is some code for what I am trying to achieve…

$stores = mysql_query("SELECT * FROM Stores");
$staff = mysql_query("SELECT * FROM Staff");

I would like to create two elements, one for stores and another for staff but I want to filter the staff based on the store client side. So if the user selects “Sydney” from the first dropdown, they are presented with only staff that work at the Sydney store in the second dropdown. Then if the user chooses “London” from the first dropdown, the Sydney staff are replaced by the London staff and so on.

My server side scripting is done with PHP and I am able to create the two dropdowns with PHP. But I am stuck on the jQuery to remove the I don’t want from the second dropdown.

I know this is possible, because I see it used all the time. I have seen lots of examples of how to manage this but none of the examples use data from the PHP array to insert the .

  • 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-13T06:44:51+00:00Added an answer on June 13, 2026 at 6:44 am

    for the secondary drop down, yes, you’ll need some ajax.

    You can create a script that go fetch the result coresponding to the store and send back the option listm witch is inserted in the ooption.

    Using jquery and php you’ll need a few thing.

    A php file to get the result and return the options. (let say getStaff.php)

    <?php 
    //get the store id by post is it is set
    if (isset($_POST['store->id']) $store_id = mysqli_real_escape_string($_POST['store_id']);
    
    //get the data !! notice the WHERE caluse
    $r = mysql_query("SELECT * FROM Staff" *WHERE store=''$store->is*);
    
    //split the data in the array
    $staffs=array();
        while ($assoc = mysql_fetch_assoc($r)) {
              //Varialbe = $assoc['colum_name'];
              $staff->id=$assoc['id'];
             $staff->name=$assoc['name'];
            //and so on for each colum in your table.
            array_push($staffs, $assoc);
       }
    
    //echo the result as option
    foreach ($staffs as $staff) echo "<option value='$staff->id'>$staff->name</option>";
    ?>
    

    In you first select, add

    onchange="$.post('getStaff.php', {store_id:$(this).val()}, function (data){ $('#staff_select').html(data);});"
    

    and add an id to your second select (staff_select) in this ecample.

    As an explanation: When the 1st dropdown change, it send a request to getStaff.php with the store_id as a POST argument. The php sript get the syaff according to the store Id and bring back a list of option tags for your secondary select. Than jquery add the ‘data’ to your secondary select and VOilà!

    Hope tih sis clear cause it’s a bunch of little thing together that will make it work. Sorry if it’s seems sloppy as an answer but it’s really simple once you know it.

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

Sidebar

Related Questions

I've been looking around but I have not found a solution for this problem:
I've been looking around for a solution to this, but haven't quite found one.
I have been looking around and found no solution for this issue. Let say
I have been looking around for a solution that implements this, but google always
Hi I have been looking around for this solution but cannot find it. Have
I have been looking around ocn Google and Stackoverflow but haven't found what I
I have been looking around on the web and found some articles about the
I have been looking around the web for this but cannot really find a
I've been looking around on-line for a solution to this, but I can't seem
I have been looking around online to try to find a complete solution but

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.