Auda com o php

23/01/2014

0

PHP

Boa noite,

Tenho que fazer uma rotina onde tenho um list/menu com os estados, e quando eu for procurar a cidade so carrega as cidades daquele determinado estado, segue o codigo:

Aqui carregas os estados
$re1 = mysql_query("select * from tb_estados order by nome");
if(mysql_errno() != 0) {
if(!isset($erros)) {
echo "Erro o arquivo init.php foi auterado, nao existe \$erros";
exit;
}
echo $erros[mysql_errno()];
exit;
}

Aqui é onde tenho que carregar as cidades vindo do campo origemuf.

$re = mysql_query("select * from tb_cidades WHERE uf =' $_GET['origemuf'] ' order by nome");
if(mysql_errno() != 0) {
if(!isset($erros)) {
echo "Erro o arquivo init.php foi auterado, nao existe \$erros";
exit;
}
echo $erros[mysql_errno()];
exit;
}

Se alguem puder me ajudar agrade.

Marcos
Marcos Amaral

Marcos Amaral

Responder

Posts

24/01/2014

Marcos Amaral

Nao tem ninguem que ajude aqui, isso ja foi bom....
Responder

24/01/2014

William

Colega Marcos peço paciência, as vezes em determinados dias da semana temos menos fluxo de usuários no fórum, nem todos acessam diariamente ou deixam a página aberta, afinal temos outros compromissos ...

Quanto a sua dúvida poste por gentileza o seu código HTML também!
Responder

24/01/2014

Marcos Amaral

<?php
if(file_exists("init.php")) {
require "init.php";
} else {
echo "Arquivo init.php nao foi encontrado";
exit;
}

if(!function_exists("Abre_Conexao")) {
echo "Erro o arquivo init.php foi auterado, nao existe a função Abre_Conexao";
exit;
}

Abre_Conexao();
$re1 = mysql_query("select * from tb_estados order by uf");
if(mysql_errno() != 0) {
if(!isset($erros)) {
echo "Erro o arquivo init.php foi auterado, nao existe \$erros";
exit;
}
echo $erros[mysql_errno()];
exit;
}

$re = mysql_query("select * from tb_cidades order by nome ");
if(mysql_errno() != 0) {
if(!isset($erros)) {
echo "Erro o arquivo init.php foi auterado, nao existe \$erros";
exit;
}
echo $erros[mysql_errno()];
exit;
}

$re3 = mysql_query("select * from tb_estados order by nome");
if(mysql_errno() != 0) {
if(!isset($erros)) {
echo "Erro o arquivo init.php foi auterado, nao existe \$erros";
exit;
}
echo $erros[mysql_errno()];
exit;
}

$re2 = mysql_query("select * from tb_cidades order by nome");
if(mysql_errno() != 0) {
if(!isset($erros)) {
echo "Erro o arquivo init.php foi auterado, nao existe \$erros";
exit;
}
echo $erros[mysql_errno()];
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/cargas.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mundo Truck - O Mundo dos Gigantes das Estradas</title>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<style type="text/css">
<!--
body {
background-color: #2A6494;
}
.style4 {font-size: small}
-->
</style></head>
<style type="text/css">

#ddblueblockmenu{
border: 1px solid black;
border-bottom-width: 0;
width: 185px;
}

#ddblueblockmenu ul{
margin: 0;
padding: 0;
list-style-type: none;
font: normal 90% 'Trebuchet MS', 'Lucida Grande', Arial, sans-serif;
}

#ddblueblockmenu li a{
display: block;
padding: 3px 0;
padding-left: 9px;
width: 169px; /*185px minus all left/right paddings and margins*/
text-decoration: none;
color: white;
background-color: #2175bc;
border-bottom: 1px solid #90bade;
border-left: 7px solid #1958b7;
}

* html #ddblueblockmenu li a{ /*IE only */
width: 187px; /*IE 5*/
w\idth: 169px; /*185px minus all left/right paddings and margins*/
}

#ddblueblockmenu li a:hover {
background-color: #2586d7;
border-left-color: #1c64d1;
}

#ddblueblockmenu div.menutitle{
color: white;
border-bottom: 1px solid black;
padding: 1px 0;
padding-left: 5px;
background-color: black;
font: bold 90% 'Trebuchet MS', 'Lucida Grande', Arial, sans-serif;
}

.style1 {
color: #FFFFFF;
font-size: small;
}
.style12 {color: #FFFFFF; font-weight: bold; }
.style13 {color: #FF0000}
</style>
<body>
<table width="1056" border="0" bordercolor="#FFFFFF" bgcolor="#2A6494">
<tr>
<td><table width="100%" border="0" bgcolor="#2A6494">
<tr>
<td width="57%" align="left" valign="top" bgcolor="#2A6494"><div align="left">
<div align="left">
<div align="left">
<table width="100%" border="0" bgcolor="#FFFFFF">
<tr>
<td><img src="../Imagens/bannerOfi1.png" alt="" width="613" height="141" /></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><h6><span class="style14 style4 style15 style13">Reservado a sua empresa. Divulgue aqui, sua marca, seu site. 11 98568-3589 Tim</span></h6></td>
</tr>
</table>
</div>
</div>
</div></td>
<td width="12%" align="center" valign="bottom" bgcolor="#2A6494">
<!-- Widget Previsão de Tempo CPTEC/INPE -->
<iframe allowtransparency="true" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://www.cptec.inpe.br/widget/widget.php?p=244&w=p&c=748ccc&f=ffffff" height="154px" width="120px"></iframe>
<noscript>
</noscript>
<!-- Widget Previsão de Tempo CPTEC/INPE --> </td>
<td width="31%" align="left" valign="top" bgcolor="#2A6494"><div align="center"><a href="../Motorista/listar_ususario.php"><img src="../Imagens/motorista.png" width="145" height="195" /></a><a href="http://cargasfrete.com.br/"><img src="../Imagens/cargasfrete.png" width="145" height="195" /></a></div></td>
</tr>
</table></td>
</tr>
<tr>
<td width="81%" align="left" valign="top"><table width="100%" border="0" bgcolor="#FFFFFF">
<tr>
<td width="69%" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="18%" align="left" valign="top"><div id="ddblueblockmenu">
<div class="menutitle">Mundo Truck</div>
<ul>
<li><a href="cargas.php">Home</a></li>
<li><a href="Cadastra_cargas.php">Cadastre seus Fretes</a></li>
<li><a href="listar_cargas.php">fretes Disponiveis</a></li>
<li><a href="../fotos.php"></a></li>
<li><a href="http://www.mundotruck.com.br/phpBB3/"></a></li>
<li><a href="../index.php">Mundo Truck</a></li>
</ul>
<div class="menutitle"></div>
<ul>
</ul>
</div></td>
<td width="82%" align="left" valign="top"><!-- InstanceBeginEditable name="EditRegion2" -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="top">
<form action="inserir_cargas.php" method="post">
<div > <br />
<table width="89%" border="0" align="center" cellpadding="0" cellspacing="0" onfocus="MM_validateForm('dia','','R','mes','','R','ano','','R','carga','','R','peso','','R','valor','','R','veiculo','','R','carroceria','','R','especie','','R','contato','','R','email','','R','telefone','','R','celular','','R','nextel','','R','site','','R','facebook','','R','obs','','R');return document.MM_returnValue">
<tr>
<td colspan="2" bgcolor="#2A6494"><div align="center" class="style5 style6">Dados da Carga</div></td>
</tr>
<tr>
<td colspan="2"><div align="center" class="style5">(*) Campos Obrigatórios</div></td>
</tr>
<tr>
<td>Data</td>
<td><label>
<input name="dia" type="text" id="dia" size="2" maxlength="2" />
/
<input name="mes" type="text" id="mes" size="2" maxlength="2" />
/
<input name="ano" type="text" id="ano" value="2014" size="6" maxlength="6" />
<span class="style5">*</span></label></td>
</tr>
<tr>
<td>Origem</td>
<td>
UF
<label>
<select name="origemuf" id="origemuf" class="textBox">
<option>AC</option>
<option>AL</option>
<option>AM</option>
<option>AP</option>
<option>BA</option>
<option>CE</option>
<option>DF</option>
<option>ES</option>
<option>GO</option>
<option>MA</option>
<option>MG</option>
<option>MS</option>
<option>MT</option>
<option>PA</option>
<option>PB</option>
<option>PE</option>
<option>PI</option>
<option>PR</option>
<option>RJ</option>
<option>RN</option>
<option>RO</option>
<option>RR</option>
<option>RS</option>
<option>SC</option>
<option>SE</option>
<option>SP</option>
<option>TO</option>

</select>
/ Estado
<select name="origem" id="origem" class="textBox" >
<?php

while($l = mysql_fetch_array($re))
{ $id = $l["id"];
$nome = $l["nome"];
echo "<option value=\"$id\">$nome</option>\n";}
@mysql_close();
?>
</select>
<span class="style5">*</span></label></td>
</tr>
<tr>
<td>Destino</td>
<td>
UF
<label>
<select name="destinouf" id="destinouf" class="textBox">
<option>AC</option>
<option>AL</option>
<option>AM</option>
<option>AP</option>
<option>BA</option>
<option>CE</option>
<option>DF</option>
<option>ES</option>
<option>GO</option>
<option>MA</option>
<option>MG</option>
<option>MS</option>
<option>MT</option>
<option>PA</option>
<option>PB</option>
<option>PE</option>
<option>PI</option>
<option>PR</option>
<option>RJ</option>
<option>RN</option>
<option>RO</option>
<option>RR</option>
<option>RS</option>
<option>SC</option>
<option>SE</option>
<option>SP</option>
<option>TO</option>
<?php

while($l = mysql_fetch_array($re3))
{ $id = $l["id"];
$nome = $l["uf"];
echo "<option value=\"$id\">$nome</option>\n";}
@mysql_close();
?>
</select>
/ Estado
<select name="destino" id="destino" class="textBox" >
<?php

while($l = mysql_fetch_array($re2))
{ $id = $l["id"];
$nome = $l["nome"];
echo "<option value=\"$id\">$nome</option>\n";}
@mysql_close();
?>
</select>
<span class="style5">*</span></label></td>
</tr>
<tr>
<td width="90">Carga</td>
<td width="673"><label>
<input name="carga" type="text" id="carga" size="100" maxlength="100" />
<span class="style5">*</span>
</label> </td>
</tr>
<tr>
<td>Peso </td>
<td><label>
<input name="peso" type="text" id="peso" size="3" maxlength="3" />
Toneladas <span class="style5">*</span> </label></td>
</tr>
<tr>
<td width="90">Valor</td>
<td width="673"><label>R$
<input name="valor" type="text" id="valor" size="9" maxlength="9" />
</label>
,00 <span class="style5">*</span> </td>
</tr>
<tr>
<td>Rastreado</td>
<td><label>
<input name="rastreado" type="text" id="rastreado" size="4" />
<span class="style5">*</span></label></td>
</tr>
<tr>
<td>Agenciamento </td>
<td><label>
<input name="agenciamento" type="text" id="agenciamento" size="4" maxlength="4" />
<span class="style5">*</span></label></td>
</tr>
<tr>
<td width="90">Veiculo</td>
<td width="673"><label>
<input name="veiculo" type="text" id="veiculo" size="60" maxlength="60" />
</label>
<span class="style5">*</span> </td>
</tr>
<tr>
<td width="90">Carroceria</td>
<td width="673"><label>
<input name="carroceria" type="text" id="carroceria" size="60" maxlength="60" />
</label>
<span class="style5">*</span> </td>
</tr>
<tr>
<td width="90">Especie</td>
<td width="673"><label>
<input name="especie" type="text" id="especie" size="60" maxlength="60" />
</label>
<span class="style5">*</span> </td>
</tr>
<tr>
<td width="90">OBS</td>
<td width="673"><label>
<textarea name="obs" cols="50" rows="3" id="obs"></textarea>
</label>
<span class="style5">* </span></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#2A6494"><div align="center"><span class="style7">Dados do Contato</span></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="90">Contato</td>
<td width="673"><label>
<input name="contato" type="text" id="contato" size="100" maxlength="100" />
</label>
<span class="style5">*</span> </td>
</tr>
<tr>
<td width="90">E-mail</td>
<td width="673"><label>
<input name="email" type="text" id="email" size="100" maxlength="100" />
</label>
<span class="style5">*</span> </td>
</tr>
<tr>
<td width="90">Telefone</td>
<td width="673"><label>
<input name="telefone" type="text" id="telefone" size="100" maxlength="100" />
</label>
<span class="style5">*</span> </td>
</tr>
<tr>
<td>Celular</td>
<td><label>
<input name="celular" type="text" id="celular" size="100" maxlength="100" />
<span class="style5">*</span></label></td>
</tr>
<tr>
<td>Nextel</td>
<td><label>
<input name="nextel" type="text" id="nextel" size="50" maxlength="50" />
<span class="style5">*</span></label></td>
</tr>
<tr>
<td>Site</td>
<td><label>
<input name="site" type="text" id="site" size="100" maxlength="100" />
<span class="style5">*</span></label></td>
</tr>
<tr>
<td>Facebook</td>
<td><p>
<label>
<input name="facebook" type="text" id="facebook" size="100" maxlength="100" />
</label>
<span class="style5">*</span></p> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#2A6494"> </td>
</tr>
<tr>
<td height="62" colspan="2"><label>
<div align="center">
<input type="submit" name="button" id="button" value="Cadastrar" />
</div>
</label> </td>
</tr>
</table>
<br />
</div>
<div id='rodape'></div>
</form></td>
</tr>
</table>

<style type="text/css">
<!--
#cabec {
height: 150px; /* ALtura*/
background-color: white; /* fundo*/
text-align:right;
background:url(Imagens/topo.png) no-repeat;
}
#cabec {
height: 150px; /* ALtura*/
background-color: white; /* fundo*/
text-align:right;
background:url(Imagens/topo.png) no-repeat;
}
#rodape { clear:both; /* Cancela flutuacao*/
font-family: arial;
font-size: 12px; /* Altura da fonte*/
background-color: silver;
text-align:center; /* Centraliza texto*/
}
.textBox {border:1px solid gray; width:200px;}
.style5 {
color: #0000FF;
font-weight: bold;
}
.style6 {color: #FFFFFF}
.style7 {color: #FFFFFF; font-weight: bold; }
-->
</style>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#2A6494"><div align="center"><span class="style3 style1">Todos os direitos reservados ao Mundo Truck/2014</span></div></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
Responder

25/01/2014

Marcus Santos

Olá Marcos, bom dia !

quando tive essa dúvida usei os seguintes sites como referência, me ajudaram bastante, espero que te ajude também.

Carregar Combobox de Cidades/Estado
Populando Select com Ajax

Após ler e seguir esses exemplos, caso tenha dúvidas por favor me avise.

Abs
Responder

26/01/2014

Marcos Amaral

Marcus boa noite,

Agradeço sua ajuda, consegui fazer a rotina certinha, unica coisa que nao consigo gravar no banco a informação.

De qual campo que tenho que pegar para gravar o id da cidade.

Abraços

Marcos
Responder

28/01/2014

Marcos Amaral

Boa tarde, podem dar como concluido esse post, os exemplos que o Marcus passou foi muito utim e me ajudou bastante...

Obrigado
Responder

29/01/2014

William

Encerrando o tópico!
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar