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 Answer