我正在尝试从第一个投递箱中过滤出第二个投递箱。第一个$box1
工作正常。但是我无法$box2
建立第一个。如果我改变
SELECT Site FROM companiesandsitessql WHERE Company ='$box1'");
到
SELECT Site FROM companiesandsitessql WHERE Company =”CompanyA);
然后它将 CompanyA 的所有站点拉到第二个框中。我已经尝试了很多变体,$box1
但我一定错过了一些东西。任何想法表示赞赏。
<?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;
?>