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

时间:2021-05-02

如下所示:

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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表形成缓存的程序实例代码全部内容了,希望大家多多支持服务器之家~

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章