PHP根据分类分别生成js缓存文件

//生成分类 缓存
    $sql = "SELECT catid FROM `category`";
    $r = $db->query($sql);
    $row=$db->fetchALL($r);

    for ($i=0; $i $row) ;$i++) { 

        $v = $row[$i]['catid'];
        $c_sql = "SELECT id,catid,name FROM `address_list` where catid = ".$v;
        $c_r = $db -> query($c_sql);
        $c_rs = $db->fetchAll($c_r);
        //循环文件内容
        for ($j=0; $j $c_rs) ; $j++) { 
            $cons[$i].= '{"id":"'.$c_rs[$j][id].'","catid":"'.$c_rs[$j][catid].'","label":"'.$c_rs[$j][name].'"},';
        }
        $content = "var colors = [".$cons[$i]."]";
        //生成文件
        $fdir = "./caches/";
        $fname = "cache_category_".$v.".js";
        $dir = $fdir.$fname;
        $fp =fopen($dir,"w+");

        if(false!=$fp){
            fwrite($fp,$content,strlen($content));
            fclose($fp);
            echo success('生成成功',"?action=address");
        }

    }

你可能感兴趣的:(从入门到放弃)