嗨,我有一个下拉列表,它将从表 (data_builder) 中检索值,并希望从另一个表 (data_suburb) 中合并现有郊区。因此,当我单击下拉列表时,它将显示所选郊区和 data_suburb 中的所有郊区
我有的例子:
表(data_builder)
<b>id | builder_name | builder_suburb | builder_state | builder_postcode</b><br>
1 | Biz Shop | Richmond | VIC | 3121<br>
2 | Tony Sykes | Melbourne | VIC | 3000<br>
3 | HDI Group | Abbotsford | VIC | 3607<br>
ETC...
表(data_suburb)
<b>id | suburb | suburb_state | suburb_postcode</b><br>
1 | Abbotsford | VIC | 3067<br>
2 | Aberfeldie | VIC | 3040<br>
3 | Aberfeldy | VIC | 3825<br>
ETC...
这是我尝试过的代码
include $_SERVER['DOCUMENT_ROOT']."/includes/conn.php";
$id =$_REQUEST['id'];
$result = mysql_query("SELECT * FROM data_builder WHERE id = '$id'");
$retrieve = mysql_fetch_array($result);
$BuildSuburb=$retrieve['builder_suburb'] ;
echo "<select name='buildersuburb'>";
$query="SELECT suburb FROM data_suburbs ORDER BY suburb ASC";
$result = mysql_query($query);
if(!$result){
die ("Could not query the database: <br />" . mysql_error());
}
while ($data=mysql_fetch_array($result)){
echo '<option value="' . $data[suburb];
if($data[suburb]=$BuildSuburb): echo $data[suburb] . '"' . 'selected="selected"';
else: echo $data[suburb] . '"';
endif;
echo '" >' . $data[suburb] . '</option>'. "\n";
}
echo "</select>";