1. 程式人生 > >php 二維陣列入mysql 資料庫

php 二維陣列入mysql 資料庫

<html>
<head> <meta http-equiv=content-type content="text/html; charset=GBK">
<title>planar array insert into db </title>
</head>
<body>
<?php

include('/home/xiaocong#######');

$myconn=mysql_connect("####","###","###");
mysql_select_db("####_bi",$myconn);

$process=array();
echo $process[0];
echo $process[1];
echo "<br>";

$source_file="#########l".$filename;   //檔案地址

if(!$source_file)
{
    echo'檔案不存在';
}
else
{
    unlink($source_file);
}
$file_pointer = fopen($source_file, "a");     //引數 a  追加  w 新寫入


//$country=array('lid_50001'=>array('uid'=>'root', 'class'=>1,'value'=>'中國'),
//'lid_53297'=>array('uid'=>'root', 'class'=>1,'value'=>'泰國'));
for(reset($country);$key=key($country);next($country))
{
        echo "key=" . $key;
        echo "<br>";
        $lid=$country[$key];
        while(list($uid,$value)=each($lid))
        {
            echo $uid . ":";
            echo $value;
            echo "<br>";
            array_push($process,$value);
        }

        echo "class:" . $process[1] . "value:" . $process[2] . "<br>";
        $temp_str=substr($key,-5);
        $insertDB="insert into t_qeesoo_CPD (Cuid,class,Cvalue) values('$temp_str','$process[1]','$process[2]')";
        echo $insertDB;
        mysql_query($insertDB);
        fwrite($file_pointer, $insertDB);
        fwrite($file_pointer, ";/n"); 
       
        $process=array();
    //    mysql_query("source /home/xiaocong/public_html/planar_array.sql");
        echo   "<br>";
}
//echo count($country);
echo   "<br>";

//$province = array(
//'lid_50002'=>array('uid'=>'50001', 'class'=>2,'value'=>'山東省'),
//'lid_50160'=>array('uid'=>'50001', 'class'=>2,'value'=>'江西省'));


$process=array();
for(reset($province);$key=key($province);next($province))
{
        echo "key=" . $key;
        echo "<br>";
        $lid=$province[$key];
        while(list($uid,$value)=each($lid))
        {
            echo $uid . ":";
            echo $value;
            echo "<br>";
            array_push($process,$value);
        }

        echo "class:" . $process[1] . "value:" . $process[2] . "<br>";
        $temp_str=substr($key,-5);
        $insertDB_2="insert into t_qeesoo_CPD (Cuid,Puid,class,Pvalue) values('$process[0]','$temp_str','$process[1]','$process[2]')";
    //    echo $insertDB;

        fwrite($file_pointer, $insertDB_2);
        fwrite($file_pointer, ";/n"); 
       
        $process=array();
        echo   "<br>";
}
//fwrite($file_pointer, "*************************************");

//$city = array(
//'lid_50003'=>array('uid'=>'50002', 'class'=>3,'value'=>'濟南','citycode'=>'0531'),
//'lid_50014'=>array('uid'=>'50002', 'class'=>3,'value'=>'青島','citycode'=>'0532'));

$process=array();

for(reset($city);$key=key($city);next($city))
{
        echo "key=" . $key;
        echo "<br>";
        $lid=$city[$key];
        while(list($uid,$value)=each($lid))
        {
            echo $uid . ":";
            echo $value;
            echo "<br>";
            array_push($process,$value);
        }

        echo "class:" . $process[1] . "value:" . $process[2] . "<br>";
        $temp_str=substr($key,-5);
        $insertDB_3="insert into t_qeesoo_CPD (Puid,Cityuid,class,Cityvalue) values('$process[0]','$temp_str','$process[1]','$process[2]')";
    //    echo $insertDB;

        fwrite($file_pointer, $insertDB_3);
        fwrite($file_pointer, ";/n"); 
       
        $process=array();
        echo   "<br>";
}

//$district = array(
//'lid_50004'=>array('uid'=>'50003', 'class'=>4,'value'=>'歷下區'),
//'lid_50005'=>array('uid'=>'50003', 'class'=>4,'value'=>'市中區'));

$process=array();

for(reset($district);$key=key($district);next($district))
{
        echo "key=" . $key;
        echo "<br>";
        $lid=$district[$key];
        while(list($uid,$value)=each($lid))
        {
            echo $uid . ":";
            echo $value;
            echo "<br>";
            array_push($process,$value);
        }

        echo "class:" . $process[1] . "value:" . $process[2] . "<br>";
        $temp_str=substr($key,-5);
        $insertDB_4="insert into t_qeesoo_CPD (Cityuid,Duid,class,Dvalue) values('$process[0]','$temp_str','$process[1]','$process[2]')";
    //    echo $insertDB;

        fwrite($file_pointer, $insertDB_4);
        fwrite($file_pointer, ";/n"); 

        $process=array();
        echo   "<br>";
}

/*
$query="select * from t_qeesoo_visitdata limit 0,10";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))//通過迴圈讀取資料內容
{
?>
    <tr>
    <td align="center" height="19"><?echo $row["id"]?></td>
    <td align="center"><?echo $row["guid"]?></td>
    <td align="center"><?echo $row["src_ip"]?></td>
    <td align="center"><?echo $row["src_href"]?></td>
    <td align="center"><?echo $row["referrer"]?></td>
    <td align="center"><?echo $row["start_time"]?></td>
    <td align="center"><?echo $row["type"]?></td>
    <td align="center"><?echo $row["state"]?></td>
    </tr>
<?php
}

*/
//關閉對資料庫的連線
mysql_close($myconn);

?>
</body>
</html>