遍历echsop的region表形成缓存的程序实例代码

5年以前  |  阅读数:881 次  |  编程语言:PHP 

如下所示:


    header("Content-type: text/html; charset=utf-8"); 
    $con = mysql_connect("localhost","root","root");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("ecshop", $con);

    $result = mysql_query("SELECT * FROM ecs_region where region_type=1");
    $data=array();
    while($row = mysql_fetch_array($result))
    {
    $data1=array();
    $data1["itemName"]=$row["region_name"];
    $data1["itemCode"]=$row["region_id"];
    $data1["list"]=array();
    $data[]=$data1;
    unset($data1);
    }
    foreach ($data as $key => $value) {
    $result1 = mysql_query("SELECT * FROM ecs_region where parent_id=".$value["itemCode"]);
    while($row1 = mysql_fetch_array($result1))
    {
    $data1=array();
    $data1["itemName"]=$row1["region_name"];
    $data1["itemCode"]=$row1["region_id"];
    $data1["list"]=array();
    $result2 = mysql_query("SELECT * FROM ecs_region where parent_id=".$row1["region_id"]);
    while($row2 = mysql_fetch_array($result2))
    {
    $data2=array();
    $data2["itemName"]=$row2["region_name"];
    $data2["itemCode"]=$row2["region_id"];
    $data2["list"]=array();
    $data2["list"]=$data2["list"];
    $data1["list"][]=$data2;
    unset($data2);
    }
    //$data[$key]["list"][]=json_encode($data1);
    $data[$key]["list"][]=$data1;
    unset($data1);

    }
    }
    // foreach ($data as $key => $value) {
    // $data[$key]["list"]=json_encode($data[$key]["list"]);
    // }
    put_content(json_encode($data));
    function put_content($levelconfig) {

    $message="<?php \n";
    $message.="\$address_config = '";
    $message .= $levelconfig;
    $message .="';";
    $message.="\n?> ";
    $fold = "address_config.php";
    $stderr = fopen($fold, 'w+');
    fwrite($stderr, $message);
    fclose($stderr);
    }
    mysql_close($con);
    ?>

以上就是小编为大家带来的遍历echsop的region表形成缓存的程序实例代码全部内容了,希望大家多多支持脚本之家~

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例