Tenho o seguinte código abaixo. Fiz uma consulta ao banco, porem não aparece os registros na combo, fiz um teste para ser exibido em uma tabela rodou numa boa.
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
$servidor = 'localhost';
$usuario = 'root';
$senha = 'elohim';
$banco = 'bd_teste';
$link = mysql_connect($servidor, $usuario, $senha)
or die ('Não foi possivel conectar ao Banco MTI: '.mysql_error());
$select = mysql_select_db($banco);
?>
<select name="livros">
<option >### LIVROS ###</option>
<?php
$result = mysql_query("SELECT * from tab_livros ORDER BY livro");
$linhas = mysql_num_rows($result);
for ($i=0; $i<$linhas; $i++)
{
$reg = mysql_fetch_array($result);
/* while ($linha = mysql_fetch_array($result)) { */
?>
<option value="<?php echo $reg["livro"];?>"></option>
</select>
<?php
}
mysql_close($link);
?>
</table>
<br />
<br />
<a href="inserir.php">Clique aqui para inserir novo registro.</a>
<body>
</html>
Pergunta
Martinsrj
Olá pessoal!
Tenho o seguinte código abaixo. Fiz uma consulta ao banco, porem não aparece os registros na combo, fiz um teste para ser exibido em uma tabela rodou numa boa.
<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <?php $servidor = 'localhost'; $usuario = 'root'; $senha = 'elohim'; $banco = 'bd_teste'; $link = mysql_connect($servidor, $usuario, $senha) or die ('Não foi possivel conectar ao Banco MTI: '.mysql_error()); $select = mysql_select_db($banco); ?> <select name="livros"> <option >### LIVROS ###</option> <?php $result = mysql_query("SELECT * from tab_livros ORDER BY livro"); $linhas = mysql_num_rows($result); for ($i=0; $i<$linhas; $i++) { $reg = mysql_fetch_array($result); /* while ($linha = mysql_fetch_array($result)) { */ ?> <option value="<?php echo $reg["livro"];?>"></option> </select> <?php } mysql_close($link); ?> </table> <br /> <br /> <a href="inserir.php">Clique aqui para inserir novo registro.</a> <body> </html>Link para o comentário
Compartilhar em outros sites
5 respostass a esta questão
Posts Recomendados
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.