Jump to content

[Resolvido] Erro no select!


Recommended Posts

Posted

Fala galera! estou com um problema que não consigo resolver e peço a ajuda de todos, estou tentando pegar o valor do select aluno do código abaixo que é gerado por uma outra página .php, é um combo dinâmico onde o select turma gera o aluno, e abaixo eu tenho o código pra imprimir as notas do aluno, mas o valor do select aluno nunca é obtido na página, gostaria que vocês dessem uma olhada. Desde já agradeço.

<div class="container">
<div class="span12">
   <h1><img src="images/nota.png" width="70" height="70" /> Notas</h1>
   <p>Buscar Notas de Aluno</p>
<div class="hero-unit">
   <form method="post" action="" name="lista">
   Selecione a Turma do Aluno:<br />
   <select name="turma" id="turma">
   <option value="0">Selecione a turma...</option>
   <?php
       mysql_connect('localhost','root','');
       mysql_selectdb('softacademico');
       $result = mysql_query("select * from turma");
       while($row = mysql_fetch_array($result) ){
           echo "<option value='".$row['id']."'>".utf8_encode($row['serie'])."</option>";
       }

   ?>
</select>
<br />

   Aluno:<br />
   <select name="aluno" id="aluno">
       <option value="0">Selecione a aluno...</option>
   </select><br/>

           <button type="submit" class="btn btn btn-primary">Buscar Notas >></button>

</form>
<?php
       $aluno_id = 0;
   if(isset($_POST['lista'])){
   $aluno_id = $_POST['aluno'];// não consigo pegar esse valor
}


if($aluno_id != 0){?>
<table class="table table-striped table-bordered">
<thead>
<tr>
   <th class="span1"><center>Aluno</center></th>
   <th class="span2"><center>Valor</center></th>
   <th class="span2"><center>Turma</center></th>
   <th class="span3"><center>Disciplina</center></th>
   <th class="span1"><center>Bimestre</center></th>
   <th class="span1"><center>Feedback</center></th>
   <th class="span1"><center>Editar</center></th>
   <th class="span1"><center>Apagar</center></th>
</tr>
</thead>
<tbody>
<?php
$lista = $daonotas->listaNotas($aluno_id);
   for($i = 0; $i < sizeof($lista); $i++){
   $nome = $daoalunos->buscaNome($lista[$i]->aluno_id);
   $turma = $daoturmas->buscaNome($lista[$i]->turma_id);
   $disciplina = $daodisciplinas->buscaNome($lista[$i]->disciplina_id);

?>
<tr>
<td><center><h6><?php echo $nome ?></h6></center></td>
<td><center><h6><?php echo $lista[$i]->valor ?></h6></center></td>
<td><center><h6><?php echo $turma ?></h6></center></td>
<td><center><h6><?php echo $disciplina ?></h6></center></td>
<td><center><h6><?php echo $lista[$i]->bimestre ?></h6></center></td>
<td><center><h6><?php echo $lista[$i]->feedback ?></h6></center></td>
   <td>
       <a class="btn btn-block btn-info" href="<?php echo 'editar_nota.php?id=' . $lista[$i]->id;?>">
       <i class="icon-pencil icon-white"></i>
       </a>
       </td>
       <td>
       <a class="btn btn-block btn-info" href="<?php echo 'excluir_nota.php?id=' . $lista[$i]->id;?>">
       <i class="icon-remove icon-white"></i>
       </a>
       </td>
</tr>
<?php } ?><!--fechamento do for-->

   </tbody>
</table>
<?php } else{echo "Nada Consta!";}?><!--fechamento do if-->



   <center><a href="cadastro_form_nota.php"><img src="images/nota2.png" width="80" height="80"/></a></center>
   <center><a href="cadastro_form_nota.php">Cadastrar Nova Nota</a></center><br/>
Posted

Não entendi o que você falou, estou pegando o form na mesma página, vou colocar o código da função Javascript que manda pra página .php que preenche o select, e também postarei a página .php.

Função Javascript

    $(document).ready(function(){
          $('#turma').change(function(){
           $('#aluno').html("<option value='0'>Carregando...</option>");

          setTimeout(function(){
              $('#aluno').load('alunos.php?idturma='+$('#turma').val() );
          }, 2000)
          });
      });

Página que recebe o valor do select turma

<?php
$id = $_GET['idturma'];
      mysql_connect('localhost','root','');
      mysql_selectdb('softacademico');

     $result = mysql_query("SELECT * FROM aluno WHERE turma_id =$id");
     while($row = mysql_fetch_array($result) ){
          echo "<option value='".$row['id']."'>".utf8_encode($row['nome'])."</option>";
     }
?>

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.