西部数码主机 | 阿里云主机| 虚拟主机 | 服务器 | 返回乐道官网
当前位置: 主页 > php教程 > ecshop教程 >

遍历ecshop的region表形成缓存的程序

时间:2016-06-13 07:26来源:未知 作者:好模板 点击:
遍历ecshop的region表形成缓存的程序,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_q
遍历ecshop的region表形成缓存的程序,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);
?>

(责任编辑:好模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------