Jump to content
Fórum Script Brasil
  • 0

Ajuda com <select>


bOnIn

Question

achei um <select> na net que pega todas as cidades do banco de dados

$html.="Você está em: <select class='itp' id='ini_cidades'>";

$query = "SELECT * FROM tb_cidades ORDER BY nome";

$resultado = mysql_query($query,$GLOBALS['conexao']);

while($linha = mysql_fetch_object($resultado)){

$html.="<option value='".$linha->nome."'>".$linha->nome."</option>";

}

$html.="</select> ";

mas eu queria colocar em html e não php como ficaria??

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

separa os código parcero.

<?php
function PreencheSelect() {
$arr = array();
$query = "SELECT * FROM tb_cidades ORDER BY nome";
$resultado = mysql_query($query,$GLOBALS['conexao']);
while($linha = mysql_fetch_arrayt($resultado)){
   $arr[] = $linha;
}
return $arr;
}
depois é só fazer um loop foreach;
<body>
  <select name="my_select>
    <?php foreach($PreecheSelect() as $rows) : ?>
        <option value="<?php echo $rows['uf'] ?>"> <?php echo $rows['cidade'] ?> </option>
        <?php endforeach; ?>
  </select>
</body>

Sacou?

Abs.

Edited by Ricardo T. do Prado
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...