日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 商务网站购物车联动地址

發布時間:2023/12/18 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 商务网站购物车联动地址 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

數據表如下:

CREATE TABLE IF NOT EXISTS `china` (
`region_id` smallint(5) unsigned NOT NULL,
? `parent_id` smallint(5) unsigned NOT NULL DEFAULT '0',
? `region_name` varchar(120) NOT NULL DEFAULT '',
? `region_type` tinyint(1) NOT NULL DEFAULT '2',
? `agency_id` smallint(5) unsigned NOT NULL DEFAULT '0'
) ENGINE=MyISAM? DEFAULT CHARSET=utf8;

?數據見文件:

測試頁test.php,

在這個文件得先引入 jquery文件和相應的js文件(accoun_1.js),

用 ajax技術查找(ajax_1.php)

test.php文件如下

<?php
session_start();
$link = mysql_connect('localhost', 'root', '123456') or die("Error: " . mysql_error());
mysql_select_db('trade', $link);
mysql_query("set names utf8", $link);
$province = array();
$sql = "select * from china where parent_id = 1";

$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
?? ?$province[$row['region_id']] = $row;
}

?>
<script src="jquery-1.10.2.js" type="text/javascript"></script>
<script src="accoun_1.js" type="text/javascript"></script>
<center>
<form name="myform" action="deal.php" method="post">
<input type="hidden" value="ajax_1.php" id="site_url">
?? ?<div id="box">
?????? ??? ??? ?<div class="tr china len2">
?????? ??? ??? ??? ?<span><b></b>省份:</span>
?????? ??? ??? ??? ?<select name="province" class="province option">
?????? ??? ??? ??? ??? ?<option>-請選擇省-</option>
??????????????????????? <?php foreach ($province as $key => $value):?>
?????? ??? ??? ??? ??? ?<option><?php echo $value['region_name'];?></option>
??????????????????????? <?php endforeach;?>
?????? ??? ??? ??? ?</select>
?????? ??? ??? ??? ?<select name="city"? class="city option">
?????? ??? ??? ??? ??? ?<option>-請選擇市-</option>
?????? ??? ??? ??? ?</select> ?
??????? ??? ??? ??? ?<select name="county"? class="county option">
?????? ??? ??? ??? ??? ?<option>-請選擇區/縣-</option>
?????? ??? ??? ??? ?</select>????? ??? ??? ??? ????? ??? ??? ??? ?
?????? ??? ??? ?</div>
?????? ??? ??? ?<div class="address len2">
?????? ??? ??? ??? ?<span><b></b>地址:</span>
?????? ??? ??? ??? ?<textarea name="address"></textarea>
?????? ??? ??? ?</div>
</div>
<input type="submit" name="submit" value="submit" />
</form>
</center>

acoun_1.js文件如下:

// id = 1為省份,2為城市

$(document).ready(function(){
?? ?var Iprovince=$('#box .china .province');
?? ?var Icity=$('#box .china .city');
?? ?var Icounty=$('#box .china .county');
?? ?var address = $('#box .address textarea');

?? ?Iprovince.change(function(){
?? ??? ?var province = $(this).val();
?? ??? ?address.text(province);
?? ??? ?var _url = 'ajax_1.php';
?? ??? ?$.ajax({
?? ??? ??? ?url:_url,
??????????? type: 'post',
??????????? data:{'prov': province, 'id': 1},
??????????? success:function(data)
?? ??? ??? ?{
?? ??? ??? ?? Icity.append(data);
?? ??? ??? ?}
?? ??? ?});
?? ?});?? ?

?? ?Icity.change(function(){
?? ??? ?var city = $(this).val();
?? ??? ?address.text(address.text()+city);
?? ??? ?var _url = 'ajax_1.php';
?? ??? ?$.ajax({
?? ??? ??? ?url:_url,
?? ??? ??? ?type:'post',
?? ??? ??? ?data:{'city':city, 'id': 2},
?? ??? ??? ?success:function(data)
?? ??? ??? ?{
?? ??? ??? ??? ?Icounty.append(data)
?? ??? ??? ?}
?? ??? ?});
?? ??? ?
?? ?});

?? ?Icounty.change(function(){
?? ??? ?var country = $(this).val();
?? ??? ?address.text(address.text()+country);
?? ?})

});

ajax_1.php文件如下:

<?php
session_start();
$link = mysql_connect('localhost', 'root', '123456') or die("Error: " . mysql_error());
mysql_select_db('trade', $link);
mysql_query("set names utf8", $link);
// 1 表省份 2 表城市
if($_POST['id'] == 1)
{
?? ?$region_name = $_POST['prov'];
?? ?$city = '';
?? ?$sql = "select * from china where region_name = '{$region_name}'";

?? ?$result = mysql_query($sql);
?? ?$pro_row = mysql_fetch_assoc($result);
?? ?$pro_id = $pro_row['region_id'];
?? ?
?? ?$query = "select * from china where parent_id = '{$pro_id}'";
?? ?$res = mysql_query($query, $link);
?? ?while($row = mysql_fetch_assoc($res))
?? ?{
?? ??? ?$city .= '<option>' . $row['region_name'] . '</option>';
?? ?}
?? ?echo $city;
?? ?
}else if($_POST['id'] == 2)
{
?? ?$region_name = $_POST['city'];
?? ?$country = '';
?? ?$sql = "select * from china where region_name = '{$region_name}'";

?? ?$result = mysql_query($sql);
?? ?$pro_row = mysql_fetch_assoc($result);
?? ?$pro_id = $pro_row['region_id'];
?? ?
?? ?$query = "select * from china where parent_id = '{$pro_id}'";
?? ?$res = mysql_query($query, $link);
?? ?while($row = mysql_fetch_assoc($res))
?? ?{
?? ??? ?$country .= '<option>' . $row['region_name'] . '</option>';
?? ?}
?? ?echo $country;

}
?>

轉載于:https://www.cnblogs.com/lin3615/p/3817368.html

總結

以上是生活随笔為你收集整理的php 商务网站购物车联动地址的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。