10/10/2018, 11:43
[php] giúp xử lý selectbox chứa country và zone(tỉnh thành)
Mình có 2 selectbox dùng hiển thị country và zone(tỉnh thành) được lấy ra từ datbase.select box thứ 1 chứa country,selectbox thứ 2 chứa zone.mình muốn khi chọn country thì selectbox thứ 2 tự động lấy dữ liệu zone của country vừa được chọn trong selectbox thứ 1 mà không phải load lại hết trang.
Mọi người giúp với...
Database có dạng như sau:
table_country có 2 field: country_id,country_name
table_zone có 3 field: zone_id,zone_country_id,zone_name
Mọi người giúp với...
Database có dạng như sau:
table_country có 2 field: country_id,country_name
table_zone có 3 field: zone_id,zone_country_id,zone_name
Bài liên quan
<script>
function changeValue(tagId, id)
{
$("#"+ tagId).load("area.php?id="+ id);
}
</script>
<?php
/**
* area.php
* ---------------------------
* DB Name: simple
* MySql User: root
* MySql Pass: 123456
* Table: sub_area (id, area_id, title)
*/
mysql_connect("localhost", "root", "123456") or
die("Could not connect: " . mysql_error());
mysql_select_db("simple");
$id = (int)$_GET['id'];
$result = mysql_query("SELECT id, title FROM sub_area WHERE area_id=" . $id);
echo "<select name=\"box2\">";
while ($row = mysql_fetch_array($result))
{
echo "<option value=\"' . $row['id'] . '\">" . $row['title'] . "</option>"
}
echo "</select>";
?>
<select id="box1" name="box1" onchange="changeValue('box2', this.value)">
<option value="1">Việt Nam</nam>
</select>
<div id="box2">
<!-- Sẽ hiện selectbox 2 -->
</div>
làm 1 selectbox để chọn vùng miền.....
có 1 CSDL gồm
id(auto), quequan, tructhuoc(int)
1......... Ha Noi.... ......0
2.........Sai Gon... ......0
3.........My Dinh... ......1
4.........Cau Giay.. ......1
5.........Quan 10.. .......2
6.........Quan 8.... .......2
yêu cầu của bài toán đưa ra là: khi chọn Ha Noi hay Sai Gon ở box1 thì box2 sẽ hiện ra các quận huyện trực thuộc tương ứng. có thể hiểu là khi chọn Ha Noi nó sẽ đưa ra ở box2 tất cả những nơi có chỉ số trực thuộc là 1.......
ai biết giúp nhé, thanks nhiều..