Ir para conteúdo
Fórum Script Brasil
  • 0

Como Atualizar Dinamicamente


bdoweb

Pergunta

9 respostass a esta questão

Posts Recomendados

  • 0

Este script é de autoria do AAlves, e utilizo ele perfeitamente. Ve se supre suas necesidades..

pagina1 o que esta em vermelho para suas configurações de BD

<html>

<head>

<title>Documento sem t?lo</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<?

$conexao = mysql_connect("HOST","USER","SENHA")

      or die("Configurações erradas. Tente novamente!");

//selecionando o banco de dados

$db = mysql_select_db("BANCO")

  or die ("Banco de dados inexistente");

$sql = mysql_query("SELECT DISTINCT CAMPO FROM TABELA order by CAMPO PARA ORDENAR ASC");

?>

<script language="JavaScript" type="text/JavaScript">

function carregar(){

var url;

url = 'remote.php?UF='+document.Cadastro.UF[document.Cadastro.UF.selectedIndex].value;

document.Cadastro.Cidades.options.length = 0;

addItem(document.Cadastro.Cidades,"Aguarde...carregando","",false,document.Cadastro.Cidades.length)

myIframe.location = url;

document.Cadastro.Cidades.focus()

}

function inicia(){

local1 = new Array();

var maximo1, i, campo1;

local1 = myIframe.loc;

campo1 = document.Cadastro.Cidades;

maximo1 = local1.length;

document.Cadastro.Cidades.options.length = 0;

addItem(campo1,'TODAS','',false,campo1.length);

for (i=0;i<maximo1;i++){

addItem(campo1,local1[1],local1[0],false,campo1.length);

}

}

function addItem(obj,strText,strValue,blSel,intPos){

  var newOpt,i,ArTemp,selIndex;

  selIndex = (blSel)?intPos:obj.selectedIndex;

  newOpt = new Option(strText,strValue);

  Len = obj.options.length+1

  if (intPos > Len) return

  obj.options.length = Len

  if (intPos != Len) {

  ArTemp = new Array();

  for(i=intPos;i<obj.options.length-1;i++)

    ArTemp = Array(obj.options.text,obj.options.value);

  for(i=intPos+1;i<Len;i++)

    obj.options = new Option(ArTemp[i-1][0],ArTemp[i-1][1]);

  }

  obj.options[intPos] = newOpt;

  if (selIndex > intPos)

  obj.selectedIndex = selIndex+1;

  else if (selIndex == intPos)

  obj.selectedIndex = intPos;

}

</script>

</head>

<body>

<div style=DISPLAY: none; POSITION: absolute" align="left"><IFRAME src name="myIframe" id="myIframe" width="400" height="100" marginwidth="0" marginheight="0"></IFRAME></div>

<form action="remote.php" method="post" name="Cadastro">

UF:<br><select name="UF" onChange="carregar();">

<option value="">--UF--</option>

    <?

    while($linha=mysql_fetch_array($sql)) {

    echo "<option value=\"" . $linha["state] . "\">" . $linha["state"] . "</option>";

    }

    ?>

</select><br>

Cidades:<br><select name=Cidades"></select>

</form>

<?

mysql_close($con);

?>

</body>

</html>

pagina remote.php

<?

$conexao = mysql_connect("HOST","USER","SENHA")

      or die("Configurações erradas. Tente novamente!");

//selecionando o banco de dados

$db = mysql_select_db("BANCO")

  or die ("Banco de dados inexistente");

$UF = $_GET['UF];

$auxsql = "SELECT DISTINCT CAMPO FROM TABELA WHERE state='{$UF}' order by CAMPOS PARA ORDENAR";

$sql = mysql_query($auxsql);

if(!$sql){echo mysql_error();exit();}

?>

<script>

loc = new Array(<?=mysql_num_rows($sql)?>)

for (i=0; i < <?=mysql_num_rows($sql)?>; i++) {

      loc = new Array(2)

              for (j=0; j < 2; j++) {

          loc[j] = "0"

  }

}

    <? $j = 0;

    while ($linha = mysql_fetch_array($sql)) {?>

    loc[<?=$j?>][0] = "<?=$linha[0]?>";

    loc[<?=$j?>][1] = "<?=$linha[0]?>";

    <?$j++;

    }

    ?>

    parent.inicia();

<?

mysql_close($con);

?>

</script>

Se quiser ver como funcional http://www.capesp.com.br/teste_refresh.php

Ok

Qualquer duvida posta

Adailton

Link para o comentário
Compartilhar em outros sites

  • 0
Guest - Tony -
Qual a duvida....

Posta

Adailton

Olá...td legal..??

Eu segui esse esquema todo e funcionou perfeitamente como falei...mas no servidor local do meu pc....estava tranquilo....agora fui publicar o sistema na internet...e a surpresa.... não funcionou....é um sistema de categoria e subcategoria....o list menu da categoria aparece normalmente....mas do submenu aparece "aguarde....carregando".... e não sai disso....não lista as subcategorias...e agora fiquei sem saber o que fazer....pois é exatamente os mesmos arquivos e banco de dados...enfim...o que pode estar acontencendo...???

sad.gifsad.gifsad.gifsad.gifsad.gif

Link para o comentário
Compartilhar em outros sites

  • 0

Verifica a conexão com Banco, as configurações

Veja...

//no arquivo remote

$conexao = mysql_connect("HOST","USER","SENHA")

      or die("Configurações erradas. Tente novamente!");

//selecionando o banco de dados

$db = mysql_select_db("BANCO")

  or die ("Banco de dados inexistente");

ou Posta o teu codigo

Adailton

Link para o comentário
Compartilhar em outros sites

  • 0
Guest - Tony -
Verifica a conexão com Banco, as configurações

Veja...

//no arquivo remote

$conexao = mysql_connect("HOST","USER","SENHA")

      or die("Configurações erradas. Tente novamente!");

//selecionando o banco de dados

$db = mysql_select_db("BANCO")

  or die ("Banco de dados inexistente");

ou Posta o teu codigo

Adailton

Adailton....tá certinho a conexão...tanto que lista as categorias....vou postar meu cod...se você puder ajudar.... eu deixei os nomes dos campos com o que estava no tutorial... Cidades e UF mas na verdade são categoria e subcategoria....

admin.php

<? 

include("config.php");

$sql = mysql_query("SELECT * FROM categoria");  

?> 
<script language="JavaScript" type="text/JavaScript"> 
function carregar(){ 
Combo1 = document.Cadastro.UF; //ALTERE AQUI PARA SEU FORM E 1º SELECT 
Combo2 = document.Cadastro.Cidades; //ALTERE AQUI PARA SEU FORM E 2º SELECT 
var url; 
url = 'remote.php?UF='+Combo1[Combo1.selectedIndex].value; 
Combo2.options.length = 0; 
addItem(Combo2,"Aguarde...carregando","",false,Combo2.length) 
myIframe.location = url; 
Combo2.focus() 
} 

function inicia(){ 
local1 = new Array(); 
var maximo1, i; 
local1 = myIframe.loc; 
maximo1 = local1.length; 
Combo2.options.length = 0; 
addItem(Combo2,'TODAS','',false,Combo2.length); 
for (i=0;i<maximo1;i++){ 
addItem(Combo2,local1[i][1],local1[i][0],false,Combo2.length); 
} 
} 

function addItem(obj,strText,strValue,blSel,intPos){  
     var newOpt,i,ArTemp,selIndex;  
     selIndex = (blSel)?intPos:obj.selectedIndex;  
     newOpt = new Option(strText,strValue);  
     Len = obj.options.length+1  
     if (intPos > Len) return  
     obj.options.length = Len  
     if (intPos != Len) {  
          ArTemp = new Array();  
          for(i=intPos;i<obj.options.length-1;i++)  
               ArTemp[i] = Array(obj.options[i].text,obj.options[i].value);  
          for(i=intPos+1;i<Len;i++)  
               obj.options[i] = new Option(ArTemp[i-1][0],ArTemp[i-1][1]);  
     }  
     obj.options[intPos] = newOpt;  
     if (selIndex > intPos)  
          obj.selectedIndex = selIndex+1;  
     else if (selIndex == intPos)   
          obj.selectedIndex = intPos;  
}  
</script> 

</head> 

<body> 
<div style="DISPLAY: none; POSITION: absolute" align="left"> 
<IFRAME src name="myIframe" id="myIframe" width="400" height="100" marginwidth="0" marginheight="0"></IFRAME> 
</div> 
<form action="adicionarcliente.php" method="post" name="Cadastro">
<input name="adm" type="hidden" id="adm_categoria2" value="empresa">
  <table width="800" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFF66">
    <tr>
      <td height="144" colspan="3"><center> <div align="center">Categorias:<br>
          <select name="UF" onChange="carregar();">
            <option value="">--UF--</option>
            <?
    while($linha=mysql_fetch_array($sql)) {
    echo "<option value=\"" . $linha["id_categoria"] . "\">" . $linha["nome_categoria"] . "</option>";
    }
    ?>
          </select>
          <br>
          Subcategorias<br>
          <select name="Cidades">
          </select>
        </div></td>
      <p> </tr>
    <tr>
      <td>&nbsp;</td>
      </form>
<? 
mysql_close($conn); 
?> 
Remote.php
<? 

include("config.php");


$UF = $_GET['UF']; 
$auxsql = "SELECT * FROM subcategoria where id_categoria =$UF "; 
$sql = mysql_query($auxsql); 
if(!$sql){echo mysql_error();exit();} 
?> 

<script> 
   loc = new Array(<?=mysql_num_rows($sql)?>) 
   for (i=0; i < <?=mysql_num_rows($sql)?>; i++) { 
          loc[i] = new Array(2) 
                  for (j=0; j < 2; j++) { 
              loc[i][j] = "0" 
            } 
    } 

    <? $j = 0; 
      while ($linha = mysql_fetch_array($sql)) {?> 
       loc[<?=$j?>][0] = "<?=$linha[0]?>"; 
       loc[<?=$j?>][1] = "<?=$linha[1]?>"; 
       <?$j++; 
       } 
    ?> 
    parent.inicia();  
<? 
mysql_close($conn); 
?> 
</script>

O estranho é que é exatamente o mesmo script que esta no meu pc no servidor local...e funciona perfeitamente...chega no servidor de internet...e dá esse problema....seria algum problema do servidor...algo que esteja ativada que prejudica o sistema???

Agradeço novamente pela sua atençao! wink.gif

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...