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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:06:30+00:00 2026-06-16T03:06:30+00:00

First Id like to thank everyone for such positive response on my previous question.

  • 0

First Id like to thank everyone for such positive response on my previous question.

Now I got another question I need help with.

I have a dropdown menu with a list of items. The list is generated inside while loop. Here is the code:

$query = "SELECT Key, Short FROM product WHERE Active = 1 OR Short LIKE 'Blue%'";
$run = mysql_query($query) or die(mysql_error());

echo 'Product: <br />';
?>

<select id="select2" name="select2">
<?php
$ids = 0;
echo "<option selected='selected'>-Select product-</option>";
while($rows = mysql_fetch_assoc($run)) {
    echo "<option value=$ids>".$rows['Short']."</option>";
    $ids++;
}
?>
</select><br /><br />

Now what I need to do is create another dropdown menu below this one and show contracts depending on which option they selected from dropdown menu. Each item they select also have a number called Key. Now inside another table called contracts I have stored all contracts with the same value Key. So…in the second dropdown menu I have to show the contracts based on the key they selected with the item in the first dropdown menu.

I really hope it is clear enough to understand, I am a little confused.

Update: Ok, here is new code:

index.php

$("select#select2").change(function(){
    $.ajax({
        type: "GET",
        url: "process.php",
        data: "selected_key=" + $(this).val(),
        success: function(result) {
            $("select#text2").html(result);
        }
    });
});

</script>

<select id="text2" name="text2">

</select>

And here is my process.php

<?php ## URL_TO_GET_CONTRACTS_FOR_KEY ##
$selectedKey = $_GET['selected_key'];
$query = "SELECT * FROM contacts WHERE Key = '".$selectedKey."'";
$run = mysql_query($query);
while($row = mysql_fetch_assoc($run)) {
    echo "<option value='..'>..</option>";
    } ?>

But I cant see anything displayed in my text2 dropdown menu.

  • 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-16T03:06:31+00:00Added an answer on June 16, 2026 at 3:06 am

    Think you best use option value $rows[‘Key’] in first dropdown menu and add an jQuery selector that takes the selected value and gets te corresponding contracts for that key.

    Should be something like this..

    PHP CODE

    $query = "SELECT Key, Short FROM product WHERE Active = 1 OR Short LIKE 'Blue%'";
    $run = mysql_query($query) or die(mysql_error());
    echo 'Product: <br />'; ?>
    <select id="select2" name="select2">
    <?php
    echo "<option selected='selected'>-Select product-</option>";
    while($rows = mysql_fetch_assoc($run)) {
        echo "<option value='".$rows['Key']."'>".$rows['Short']."</option>";
    }
    ?>
    </select>
    

    jQUERY CODE

    $("select#select2").change(function(){
        $.ajax({
            type: "GET",
            url: "URL_TO_GET_CONTRACTS_FOR_KEY",
            data: "selected_key=" + $(this).val(),
            success: function(result) {
                $("select#NEWSELECT").html(result);
            }
        });
    });
    

    Explanation:
    URL_TO_GET_CONTRACTS_FOR_KEY is an url to a PHP file you have to write. In that file you have access to $_GET[‘selected_key’], use that value to get the contracts for that key. In that file you should echo the “” tags for the second select. Like this:

    <?php ## URL_TO_GET_CONTRACTS_FOR_KEY ##
    $selectedKey = $_GET['selected_key'];
    $query = ..
    $run = ..
    while($row = mysql_fetch_assoc($run)) {
        echo "<option value='..'>..</option>";
    } ?>
    

    NEWSELECT should be replaced by the id of the select where the returned options should be placed in.

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

Sidebar

Related Questions

First I would like to thank everyone for everything they have ever done for
Right first of I would like to thank everyone for helping me out on
First off, greetings everyone and thank you for your interest in my question. I'm
It's my first post on here, and I'd just like to thank everyone so
I have finally got my first extension built thanks to everyone here! I managed
First off I would like to say that I think that my question may
I have text file with something like first line line nr 2 line three
Let's say I have a first structure like this: typedef struct { int ivalue;
I have one binary file and I want to read this file like first
I'd like to thank everyone in advance for taking the time to review this

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.