$codigo = filter_var($_GET["codigo"], FILTER_SANITIZE_NUMBER_INT); if (!$codigo) $codigo = ""; $ano = filter_var($_GET["ano"], FILTER_SANITIZE_NUMBER_INT); if (!$ano) $ano = "2010"; if ($ano == "2010") { $tabBd = "sinopse_censo2010"; } else // outros anos da pirâmide. Só tem 2000 { $tabBd = "piramide_0_100_2000"; } include ("inc_connection.php"); if (!$codigo) { $sql = "select 'BRASIL' as NOME, sum(a.v10)+sum(a.v11) as totHomens_0_4, sum(a.v12) as totHomens_5_9, sum(a.v13) as totHomens_10_14, sum(a.v14) as totHomens_15_19, sum(a.v15) as totHomens_20_24, sum(a.v16) as totHomens_25_29, sum(a.v17) as totHomens_30_34, sum(a.v18) as totHomens_35_39, sum(a.v19) as totHomens_40_44, sum(a.v20) as totHomens_45_49, sum(a.v21) as totHomens_50_54, sum(a.v22) as totHomens_55_59, sum(a.v23) as totHomens_60_64, sum(a.v24) as totHomens_65_69, sum(a.v25) as totHomens_70_74, sum(a.v26) as totHomens_75_79, sum(a.v27) as totHomens_80_84, sum(a.v28) as totHomens_85_89, sum(a.v29) as totHomens_90_94, sum(a.v30) as totHomens_95_99, sum(a.v31) as totHomens_100, sum(a.v32)+sum(a.v33) as totMulheres_0_4, sum(a.v34) as totMulheres_5_9, sum(a.v35) as totMulheres_10_14, sum(a.v36) as totMulheres_15_19, sum(a.v37) as totMulheres_20_24, sum(a.v38) as totMulheres_25_29, sum(a.v39) as totMulheres_30_34, sum(a.v40) as totMulheres_35_39, sum(a.v41) as totMulheres_40_44, sum(a.v42) as totMulheres_45_49, sum(a.v43) as totMulheres_50_54, sum(a.v44) as totMulheres_55_59, sum(a.v45) as totMulheres_60_64, sum(a.v46) as totMulheres_65_69, sum(a.v47) as totMulheres_70_74, sum(a.v48) as totMulheres_75_79, sum(a.v49) as totMulheres_80_84, sum(a.v50) as totMulheres_85_89, sum(a.v51) as totMulheres_90_94, sum(a.v52) as totMulheres_95_99, sum(a.v53) as totMulheres_100 from ".$tabBd." a"; } else if(strlen($codigo) == '1') { $sql = "select '".utf8_decode(getNome($codigo))."' as NOME, sum(a.v10)+sum(a.v11) as totHomens_0_4, sum(a.v12) as totHomens_5_9, sum(a.v13) as totHomens_10_14, sum(a.v14) as totHomens_15_19, sum(a.v15) as totHomens_20_24, sum(a.v16) as totHomens_25_29, sum(a.v17) as totHomens_30_34, sum(a.v18) as totHomens_35_39, sum(a.v19) as totHomens_40_44, sum(a.v20) as totHomens_45_49, sum(a.v21) as totHomens_50_54, sum(a.v22) as totHomens_55_59, sum(a.v23) as totHomens_60_64, sum(a.v24) as totHomens_65_69, sum(a.v25) as totHomens_70_74, sum(a.v26) as totHomens_75_79, sum(a.v27) as totHomens_80_84, sum(a.v28) as totHomens_85_89, sum(a.v29) as totHomens_90_94, sum(a.v30) as totHomens_95_99, sum(a.v31) as totHomens_100, sum(a.v32)+sum(a.v33) as totMulheres_0_4, sum(a.v34) as totMulheres_5_9, sum(a.v35) as totMulheres_10_14, sum(a.v36) as totMulheres_15_19, sum(a.v37) as totMulheres_20_24, sum(a.v38) as totMulheres_25_29, sum(a.v39) as totMulheres_30_34, sum(a.v40) as totMulheres_35_39, sum(a.v41) as totMulheres_40_44, sum(a.v42) as totMulheres_45_49, sum(a.v43) as totMulheres_50_54, sum(a.v44) as totMulheres_55_59, sum(a.v45) as totMulheres_60_64, sum(a.v46) as totMulheres_65_69, sum(a.v47) as totMulheres_70_74, sum(a.v48) as totMulheres_75_79, sum(a.v49) as totMulheres_80_84, sum(a.v50) as totMulheres_85_89, sum(a.v51) as totMulheres_90_94, sum(a.v52) as totMulheres_95_99, sum(a.v53) as totMulheres_100 from ".$tabBd." a where LEFT(a.CODMUN,1)='".$codigo."'"; } else if(strlen($codigo) == '2') { $sql = "select '".utf8_decode(getNome($codigo))."' as NOME, sum(a.v10)+sum(a.v11) as totHomens_0_4, sum(a.v12) as totHomens_5_9, sum(a.v13) as totHomens_10_14, sum(a.v14) as totHomens_15_19, sum(a.v15) as totHomens_20_24, sum(a.v16) as totHomens_25_29, sum(a.v17) as totHomens_30_34, sum(a.v18) as totHomens_35_39, sum(a.v19) as totHomens_40_44, sum(a.v20) as totHomens_45_49, sum(a.v21) as totHomens_50_54, sum(a.v22) as totHomens_55_59, sum(a.v23) as totHomens_60_64, sum(a.v24) as totHomens_65_69, sum(a.v25) as totHomens_70_74, sum(a.v26) as totHomens_75_79, sum(a.v27) as totHomens_80_84, sum(a.v28) as totHomens_85_89, sum(a.v29) as totHomens_90_94, sum(a.v30) as totHomens_95_99, sum(a.v31) as totHomens_100, sum(a.v32)+sum(a.v33) as totMulheres_0_4, sum(a.v34) as totMulheres_5_9, sum(a.v35) as totMulheres_10_14, sum(a.v36) as totMulheres_15_19, sum(a.v37) as totMulheres_20_24, sum(a.v38) as totMulheres_25_29, sum(a.v39) as totMulheres_30_34, sum(a.v40) as totMulheres_35_39, sum(a.v41) as totMulheres_40_44, sum(a.v42) as totMulheres_45_49, sum(a.v43) as totMulheres_50_54, sum(a.v44) as totMulheres_55_59, sum(a.v45) as totMulheres_60_64, sum(a.v46) as totMulheres_65_69, sum(a.v47) as totMulheres_70_74, sum(a.v48) as totMulheres_75_79, sum(a.v49) as totMulheres_80_84, sum(a.v50) as totMulheres_85_89, sum(a.v51) as totMulheres_90_94, sum(a.v52) as totMulheres_95_99, sum(a.v53) as totMulheres_100 from ".$tabBd." a where LEFT(a.CODMUN,2)='".$codigo."'"; } else { $sql = "select a.CODMUN as CODMUN, b.NOME as NOME, a.v10+a.v11 as totHomens_0_4, a.v12 as totHomens_5_9, a.v13 as totHomens_10_14, a.v14 as totHomens_15_19, a.v15 as totHomens_20_24, a.v16 as totHomens_25_29, a.v17 as totHomens_30_34, a.v18 as totHomens_35_39, a.v19 as totHomens_40_44, a.v20 as totHomens_45_49, a.v21 as totHomens_50_54, a.v22 as totHomens_55_59, a.v23 as totHomens_60_64, a.v24 as totHomens_65_69, a.v25 as totHomens_70_74, a.v26 as totHomens_75_79, a.v27 as totHomens_80_84, a.v28 as totHomens_85_89, a.v29 as totHomens_90_94, a.v30 as totHomens_95_99, a.v31 as totHomens_100, a.v32+a.v33 as totMulheres_0_4, a.v34 as totMulheres_5_9, a.v35 as totMulheres_10_14, a.v36 as totMulheres_15_19, a.v37 as totMulheres_20_24, a.v38 as totMulheres_25_29, a.v39 as totMulheres_30_34, a.v40 as totMulheres_35_39, a.v41 as totMulheres_40_44, a.v42 as totMulheres_45_49, a.v43 as totMulheres_50_54, a.v44 as totMulheres_55_59, a.v45 as totMulheres_60_64, a.v46 as totMulheres_65_69, a.v47 as totMulheres_70_74, a.v48 as totMulheres_75_79, a.v49 as totMulheres_80_84, a.v50 as totMulheres_85_89, a.v51 as totMulheres_90_94, a.v52 as totMulheres_95_99, a.v53 as totMulheres_100 from ".$tabBd." a join municipios b where a.CODMUN='".$codigo."' and a.CODMUN=b.CODMUN"; } mysqli_select_db($link, "cidadesat2013"); $query = mysqli_query($link,$sql); $rs_mun = mysqli_fetch_array($query); $nome = utf8_encode($rs_mun["NOME"]); if (strlen($codigo) == "6") $nome .= " (".getSigla(substr($codigo, 0, 2)).")"; $grupos = array(); $grupos[0] = "0 a 4 anos"; $grupos[1] = "5 a 9 anos"; $grupos[2] = "10 a 14 anos"; $grupos[3] = "15 a 19 anos"; $grupos[4] = "20 a 24 anos"; $grupos[5] = "25 a 29 anos"; $grupos[6] = "30 a 34 anos"; $grupos[7] = "35 a 39 anos"; $grupos[8] = "40 a 44 anos"; $grupos[9] = "45 a 49 anos"; $grupos[10] = "50 a 54 anos"; $grupos[11] = "55 a 59 anos"; $grupos[12] = "60 a 64 anos"; $grupos[13] = "65 a 69 anos"; $grupos[14] = "70 a 74 anos"; $grupos[15] = "75 a 79 anos"; $grupos[16] = "80 a 84 anos"; $grupos[17] = "85 a 89 anos"; $grupos[18] = "90 a 94 anos"; $grupos[19] = "95 a 99 anos"; $grupos[20] = "Mais de 100 anos"; $totHomens = array(); $totHomens[0] = $rs_mun["totHomens_0_4"]; $totHomens[1] = $rs_mun["totHomens_5_9"]; $totHomens[2] = $rs_mun["totHomens_10_14"]; $totHomens[3] = $rs_mun["totHomens_15_19"]; $totHomens[4] = $rs_mun["totHomens_20_24"]; $totHomens[5] = $rs_mun["totHomens_25_29"]; $totHomens[6] = $rs_mun["totHomens_30_34"]; $totHomens[7] = $rs_mun["totHomens_35_39"]; $totHomens[8] = $rs_mun["totHomens_40_44"]; $totHomens[9] = $rs_mun["totHomens_45_49"]; $totHomens[10] = $rs_mun["totHomens_50_54"]; $totHomens[11] = $rs_mun["totHomens_55_59"]; $totHomens[12] = $rs_mun["totHomens_60_64"]; $totHomens[13] = $rs_mun["totHomens_65_69"]; $totHomens[14] = $rs_mun["totHomens_70_74"]; $totHomens[15] = $rs_mun["totHomens_75_79"]; $totHomens[16] = $rs_mun["totHomens_80_84"]; $totHomens[17] = $rs_mun["totHomens_85_89"]; $totHomens[18] = $rs_mun["totHomens_90_94"]; $totHomens[19] = $rs_mun["totHomens_95_99"]; $totHomens[20] = $rs_mun["totHomens_100"]; $totMulheres = array(); $totMulheres[0] = $rs_mun["totMulheres_0_4"]; $totMulheres[1] = $rs_mun["totMulheres_5_9"]; $totMulheres[2] = $rs_mun["totMulheres_10_14"]; $totMulheres[3] = $rs_mun["totMulheres_15_19"]; $totMulheres[4] = $rs_mun["totMulheres_20_24"]; $totMulheres[5] = $rs_mun["totMulheres_25_29"]; $totMulheres[6] = $rs_mun["totMulheres_30_34"]; $totMulheres[7] = $rs_mun["totMulheres_35_39"]; $totMulheres[8] = $rs_mun["totMulheres_40_44"]; $totMulheres[9] = $rs_mun["totMulheres_45_49"]; $totMulheres[10] = $rs_mun["totMulheres_50_54"]; $totMulheres[11] = $rs_mun["totMulheres_55_59"]; $totMulheres[12] = $rs_mun["totMulheres_60_64"]; $totMulheres[13] = $rs_mun["totMulheres_65_69"]; $totMulheres[14] = $rs_mun["totMulheres_70_74"]; $totMulheres[15] = $rs_mun["totMulheres_75_79"]; $totMulheres[16] = $rs_mun["totMulheres_80_84"]; $totMulheres[17] = $rs_mun["totMulheres_85_89"]; $totMulheres[18] = $rs_mun["totMulheres_90_94"]; $totMulheres[19] = $rs_mun["totMulheres_95_99"]; $totMulheres[20] = $rs_mun["totMulheres_100"]; $vMaxBarra = max( array(max($totHomens),max($totMulheres))); $corFundoGeral = "ECECED"; $corContornoFundoGeral = "000000"; $espContornoFundoGeral = 0; $corFundoGrafico_0 = "FFFFFF"; $corFundoGrafico_1 = "EEEEEE"; $corContornoFundoGrafico = "B1B3B4"; $espContornoFundoGrafico = 0.3; /* $corHomem = $_GET["corhomem"]; if (!$corHomem) $corHomem = "88C2E6"; */ $corHomem = "88C2E6"; $corContornoHomem = "78B2D6"; $espContornoHomem = 0; /* $corMulher = $_GET["cormulher"]; if (!$corMulher) $corMulher = "F9C189"; */ $corMulher = "F9C189"; $corContornoMulher = "E9B179"; $espContornoMulher = 0; $corContornoMedHomem = "FF3300"; $espContornoMedHomem = 0.5; $corContornoMedMulher = "FF3300"; $espContornoMedMulher = 0.5; $wMaxBarra = filter_var($_GET["wmaxbarra"], FILTER_SANITIZE_NUMBER_INT); if (!$wMaxBarra) $wMaxBarra = 180; $hBarra = 15; $totGeral = array_sum($totMulheres)+array_sum($totHomens); ?>
'.$grupos[$i].' | '; echo ''.number_format($totHomens[$i],0,",",".").' | '; // barra homem $msg = "Homens de ".$grupos[$i].': '.number_format($totHomens[$i],0,",",".").' habitantes ('.number_format(getPerc($totHomens[$i], $totGeral,1),1,',','.').'% do total)'; $wBarra = round($totHomens[$i]*$wMaxBarra/$vMaxBarra); if ($totHomens[$i] != 0) { //$img1 = ''.$img1.''.number_format(getPerc($totHomens[$i], $totGeral,1),1,',','.').'% | '; // barra Mulher $msg = "Mulheres de ".$grupos[$i].': '.number_format($totMulheres[$i],0,",",".").' habitantes ('.number_format(getPerc($totMulheres[$i], $totGeral,1),1,',','.').'% do total)'; $wBarra = round($totMulheres[$i]*$wMaxBarra/$vMaxBarra); if ($totMulheres[$i] != 0) { //$img1 = ''.$img1.''.number_format(getPerc($totMulheres[$i], $totGeral,1),1,',','.').'% | '; echo ''.number_format($totMulheres[$i],0,",",".").' | '; echo '
---|---|---|---|---|
Homens | Mulheres | |||
Fonte: IBGE, Censos Demográficos 2010, 2000, 1991, 1980, 1970. | //
Não há informações para este município em echo $ano; ?>.
} ?> function getNome($cod) { switch($cod) { case '': return 'Brasil'; break; case '1': return 'Região Norte'; break; case '2': return 'Região Nordeste'; break; case '3': return 'Região Sudeste'; break; case '4': return 'Região Sul'; break; case '5': return 'Região Centro-Oeste'; break; case '11': return 'Rondônia'; break; case '12': return 'Acre'; break; case '13': return 'Amazonas'; break; case '14': return 'Roraima'; break; case '15': return 'Pará'; break; case '16': return 'Amapá'; break; case '17': return 'Tocantins'; break; case '21': return 'Maranhão'; break; case '22': return 'Piauí'; break; case '23': return 'Ceará'; break; case '24': return 'Rio Grande do Norte'; break; case '25': return 'Paraíba'; break; case '26': return 'Pernambuco'; break; case '27': return 'Alagoas'; break; case '28': return 'Sergipe'; break; case '29': return 'Bahia'; break; case '31': return 'Minas Gerais'; break; case '32': return 'Espírito Santo'; break; case '33': return 'Rio de Janeiro'; break; case '35': return 'São Paulo'; break; case '41': return 'Paraná'; break; case '42': return 'Santa Catarina'; break; case '43': return 'Rio Grande do Sul'; break; case '50': return 'Mato Grosso do Sul'; break; case '51': return 'Mato Grosso'; break; case '52': return 'Goiás'; break; case '53': return 'Distrito Federal'; break; } } function getSigla($cod) { switch ($cod) { case '11': $sigla = 'RO'; break; case '12': $sigla = 'AC'; break; case '13': $sigla = 'AM'; break; case '14': $sigla = 'RR'; break; case '15': $sigla = 'PA'; break; case '16': $sigla = 'AP'; break; case '17': $sigla = 'TO'; break; case '21': $sigla = 'MA'; break; case '22': $sigla = 'PI'; break; case '23': $sigla = 'CE'; break; case '24': $sigla = 'RN'; break; case '25': $sigla = 'PB'; break; case '26': $sigla = 'PE'; break; case '27': $sigla = 'AL'; break; case '28': $sigla = 'SE'; break; case '29': $sigla = 'BA'; break; case '31': $sigla = 'MG'; break; case '32': $sigla = 'ES'; break; case '33': $sigla = 'RJ'; break; case '35': $sigla = 'SP'; break; case '41': $sigla = 'PR'; break; case '42': $sigla = 'SC'; break; case '43': $sigla = 'RS'; break; case '50': $sigla = 'MS'; break; case '51': $sigla = 'MT'; break; case '52': $sigla = 'GO'; break; case '53': $sigla = 'DF'; break; } return ($sigla); } function getPerc($v, $tot, $arr) { if (!$tot) { return NULL; } else { return round($v*100/$tot, $arr); } } ?>