1
Good afternoon! I have been trying to bring information from the database user and insert it into a table that follows the bootstrap syntax. But because of the complexity of tags I end up curling up :(
The goal is: > Select a user teacher. And when he is selected, bring from the benches the usual disciplines that he had already registered.
<form class="form-horizontal" method="POST" action="php/CadastrarDisciplina.php" style="margin-top:20px;">
<fieldset>
<!-- Form Name -->
<!-- Text input-->
<div class="form-group">
<label class="col-md-3 control-label" for="nome">Professor:</label>
<div class="col-md-4">
<select id="idusuario" name="idusuario" class="form-control">
<option> Selecione o professor...</option>
<?php
//Seleciona todos os professores e lista no form
include 'php/Conexao.php';
$stmt = $conexao->prepare("SELECT * FROM usuario ");
$stmt->execute();
if($stmt->rowCount()>0){
$resultado = $stmt->fetchAll();
foreach($resultado as $linha){
?>
<option value="<?php echo $linha['idusuario']; ?>"><?php echo ($linha['nomeusuario']); ?></option>
<?php
}
}
?>
</select>
</div>
</div>
</fieldset>
<!-- Quadro com todas as disciplinas-->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel='stylesheet' type='text/css'>
<div class="container">
<div class="row">
<p></p>
<div class="col-md-7 col-md-offset-1">
<div class="panel panel-default panel-table">
<div class="panel-heading">
<div class="row">
<div class="col col-xs-6">
<h3 class="panel-title">Lista de Disciplinas</h3>
</div>
<div class="col col-xs-6 text-right">
</div>
</div>
</div>
<?php
include 'php/Conexao.php';
$stmt = $conexao->prepare("select * from disciplina");
$stmt->execute();
if($stmt->rowCount() >0){
?>
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">ID</th>
<th>Nome</th>
</tr>
</thead>
<?php
}
$resultado = $stmt->fetchAll();
foreach($resultado as $linha){
$stmt2 = $conexao->prepare("SELECT * FROM usuario_disciplina WHERE usuario_idusuario=? and disciplina_iddisciplina=?;");
$stmt2 -> bindParam(1,$idusuario);
$stmt2 -> bindParam(2,$linha['iddisciplina']);
$stmt2->execute();
$resultado2 = $stmt2->fetchAll();
?>
<tbody>
<tr>
<td align="center">
<input type="checkbox" class="form-check-input" <?php if($stmt2->rowCount()>0){echo "checked='checked'"; }?> value=<?php echo $linha["iddisciplina"]; ?>>
</td>
<td class="hidden-xs"><?php echo $linha["iddisciplina"]; ?></td>
<td><?php echo ($linha["descricaodisciplina"]); ?></td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
</div>
<button type="submit" method="POST" name="singlebutton" style="margin-left:35%;" class="btn btn-success">Salvar disciplinas</button>
</div>
</div>
</form>
Hello, Mikeli. Welcome to Stackoverflow. Some parts of the question are not properly formatted, this makes it difficult to read and understand. Regarding the question, can you handle Ajax Jquery? It would be the best and cleanest solution (my opinion)
– Jhonatan Pereira
Hello, I recommend you put the foreach inside the tbody, I didn’t quite understand your question, but I think you need an ajax,
 request with pure javascript http://blog.matheuscastiglioni.com.br/requisicoes-ajax-javascript or with jquery
– Fatasy Razer