php处理行业分类数据

 实现步骤:

1.将excel表格存储为后缀名为 .csv格式的文件;

2.将.csv格式文件导入到mysql数据库中;

3.通过条件查询将所需要的数据查出并导入另一个数据表中;

下面是一些php片段:

php处理行业分类数据
<?php
    mysql_connect("localhost", "root", "root") or
        die("Could not connect: " . mysql_error());
    mysql_select_db("test");
    mysql_query("SET NAMES ‘utf8‘");
    $result = mysql_query("SELECT col2, col5, col6 FROM category where col2!=‘‘");
    
    echo "INSERT INTO `qy_category` (`catid`, `moduleid`, `catname`, `catdir`,`linkurl`,`parentid`, `arrparentid`, `child`, `arrchildid`, `listorder`,  `seo_title`, `seo_keywords`, `seo_description`) VALUES ";

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        //printf ("ID: %s  Name: %s", $row["col2"], $row["col5"]);
        //echo "<br />";
        $result2 = mysql_query("SELECT col3, col5, col6 FROM category where col3 like ‘".$row["col2"]."%‘");
        $arr = array();
        while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) {
            if($row2["col6"]==‘‘) $row2["col6"]=$row2["col5"];
            printf ("(‘%s‘, 4, ‘%s‘, ‘%s‘, ‘list.php?catid=%s‘, ‘%s‘, ‘%s‘, 0, ‘%s‘, ‘%s‘, ‘%s‘, ‘%s‘, ‘%s‘)",$row2["col3"],$row2["col5"],$row2["col3"],$row2["col3"],$row["col2"],‘0,‘.$row["col2"].‘,‘.$row2["col3"],$row2["col3"],$row2["col3"],$row2["col5"],$row2["col5"],$row2["col6"]);
            echo ",<br />";
            $arr[]=intval($row2["col3"]);
        }
        $arrchildid = intval($row["col2"]).‘,‘.implode(‘,‘,$arr);
        if($row["col6"]==‘‘) $row["col6"]=$row["col5"];
        printf ("(‘%s‘, 4, ‘%s‘, ‘%s‘, ‘list.php?catid=%s‘, 0, 0, 1, ‘%s‘, ‘%s‘, ‘%s‘, ‘%s‘, ‘%s‘)",$row["col2"],$row["col5"],$row["col2"],$row["col2"],$arrchildid,$row["col2"],$row["col5"],$row["col5"],$row["col6"]);
        echo ",<br />";
    }

    mysql_free_result($result);
    mysql_free_result($result2);
?> 
php处理行业分类数据

 

php处理行业分类数据,布布扣,bubuko.com

php处理行业分类数据

上一篇:struts2中css,js等资源无效 非路径问题(新手问题)


下一篇:innerText和innerHTML