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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:06:08+00:00 2026-06-18T10:06:08+00:00

I’m trying to filter the second drop box off the first one. The first

  • 0

I’m trying to filter the second drop box off the first one. The first one $box1 works fine. However I can’t get $box2 to build off the first. If I change

SELECT Site FROM companiesandsitessql WHERE Company ='$box1'"); 

to

SELECT Site FROM companiesandsitessql WHERE Company =”CompanyA);

it then pulls all the sites for CompanyA in the second box. I’ve tried many variations of $box1 but I must be missing something. Any ideas a appreciated.

<?php
$dbhost  = 'localhost';
$dbname  = 'escalations';
$dbuser  = 'root';

$con = mysql_connect($dbhost, $dbuser);
 {
    $box1 = array();
    mysql_select_db('escalations');
    $result = mysql_query("SELECT distinct Company FROM companiesandsitessql");
    while($row = mysql_fetch_array($result)) { $box1[] = $row; }

}
/* Generate select box contents */
$out1 = '<select name="box1">';
$out1 .= '<option>Select Company</option>';
if (!empty($box1)) {
foreach ($box1 as $k => $v) {
    $out1 .= '<option value="'.$v['Company'].'">'.$v['Company'].'</option>';
    }
}
$out1 .= '</select>';
/* Output */
echo $out1;


 {
$box2 = array();
    mysql_select_db('escalations');
    $result2 = mysql_query("SELECT Site FROM companiesandsitessql WHERE Company        ='$box1'");
    while($row2 = mysql_fetch_assoc($result2)) { $box2[] = $row2; }

}
/* Generate select box contents */
$out2 = '<select name="box2">';
$out2 .= '<option>Site list</option>';
if (!empty($box2)) {
    foreach ($box2 as $k1 => $v) {
        $out2 .= '<option value="'.$v['Site'].'">'.$v['Site'].'</option>';
    }
}
$out2 .= '</select>';
/* Output */
echo $out2;

?> 
  • 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-18T10:06:11+00:00Added an answer on June 18, 2026 at 10:06 am
    Figured it out, here’s the code.
    
    ***File new.php***
    
    <?php
    $dbhost  = 'localhost';
    $dbname  = 'escalations';
    $dbuser  = 'root';
    
    $con = mysql_connect($dbhost, $dbuser);
    ?>
    <html>
    
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    
    function autoSubmit() {
    $.post('dropoutput.php', { name: box1form.CompanyName.value},
     function (output) {
        $('#info').html(output).show();
        });
        }
    </script>
    
    <body>
    <form name="box1form" action="insert.php" method="post">
    <?php
    
    {
     $box1 = array();
     mysql_select_db('escalations');
     $result = mysql_query("SELECT distinct Company FROM companiesandsitessql ORDER BY Company ASC");
     while($row = mysql_fetch_array($result)) { $box1[] = $row; }
    
     }
    /* Generate select box contents */
    $CompanyName = '<select name="CompanyName" onchange="autoSubmit()">';
    $CompanyName .= '<option selected="selected">Select Company</option>';
    if (!empty($box1)) {
     foreach ($box1 as $k => $v) {
        $CompanyName .= '<option value="'.$v['Company'].'">'.$v['Company'].'</option>';
      }
     }
    $CompanyName .= '</select>';
    /* Output */
    echo $CompanyName;
    
    ?>
    
    <div id="info"></div><input name="send" type="submit" value="submit"><br>
    </form>
    </body>
    </html>
    
    ***file dropoutput.php***
    
    <?php
    mysql_connect("localhost", "root", "") or die (mysql_error ());
    
    $name = mysql_real_escape_string($_POST['name']);
    
    {
    $box2 = array();
     mysql_select_db('escalations');
    $result2 = mysql_query("SELECT Site FROM companiesandsitessql WHERE Company ='$name' ORDER BY Site ASC");
    while($row2 = mysql_fetch_assoc($result2)) { $box2[] = $row2; }
    
    }
     /* Generate select box contents */
     $S = '<select name="SiteOptions[]" multiple="multiple">';
     $S .= '<option>Site list</option>';
     if (!empty($box2)) {
      foreach ($box2 as $k1 => $v) {
        $S .= '<option value="'.$v['Site'].'">'.$v['Site'].'</option>';
      }
     }
    $S .= '</select>';
    /* Output */
    echo $S;
    
    ?>
    
     ***file  insert.php...
    
    <?php
    $dbhost  = 'localhost';
    $dbname  = 'escalations';
    $dbuser  = 'root';
    $dbpass  = '';
    
    $con = mysql_connect($dbhost, $dbuser);
    
    if($con == FALSE)
    {
    echo 'Cannot connect to database' . mysql_error();
    }
    else
    {
     echo " Connected to database: ";
    }
    
    $Site = implode(', ', $_POST['SiteOptions']);
    
    
    mysql_select_db("escalations", $con);
    $sql="INSERT INTO escalationtrackersql (CompanyName, Site)
    VALUES
    ('$_POST[CompanyName]', '$Site')";
    
    echo "Added $_POST[CompanyName] ";
    print $Site;
    
    if (!mysql_query($sql, $con))
    {
    die('Error: ' . mysql_error());
    }
    
    echo "  : Escalation request successfully entered.";
    
    mysql_close($con)
    
    ?>
    
    <html>
    <head>
    <meta content="en-us" http-equiv="Content-Language">
    </head>
    <body bgcolor="#C0C0C0">
    <p>&nbsp;</p>
    <p><a href="new.php">Return to the 
      escalation request form</a>.</p>
    
      </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a simple filter from one dropdown box to another.
I'm getting follwing error while I'm trying to filter data for the second time
I am trying to filter a query by two (multi select) parameters. It works
I'm trying to use a select list to actively filter the results I get
I'm trying to join the results from one query to filter the results of
Im trying to filter rows based on a column say c1 that contains boolean
I am trying to filter a fusion table using the WHERE clause in order
i'm trying to filter the $routeParams of the data returned from the json file.
I am trying to filter result from JSON string based on status selection. I
I'm trying to filter a datatable with following code private void Filter(string text) {

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.