1
Man select is wrong. How do I view this user’s dependents: I have 1 user: (Mauro Santos) and 2 dependents: (Thiago and Dhalila), how do I view on view.
Select
SELECT * FROM cad_lideranca WHERE numerocontrato = :numerocontrato
View code
<?php
require_once './config.php';
include './header.php';
try {
$sql = "SELECT * FROM cad_lideranca WHERE numerocontrato = :numerocontrato";
$stmt = $DB->prepare($sql);
$stmt->bindValue(":numerocontrato", intval($_GET["numerocontrato"]));
$stmt->execute();
$results = $stmt->fetchAll();
} catch (Exception $ex) {
echo $ex->getMessage();
}
?>
<div class="row">
<ul class="breadcrumb">
<li><a href="index.php">Início</a></li>
<li class="active">Informações</li>
</ul>
</div>
<div class="row">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Informações</h3>
</div>
<div class="panel-body">
<form class="form-horizontal" name="contact_form" id="contact_form" enctype="multipart/form-data" method="post" action="process_form.php">
<fieldset>
<div class="form-group">
<label class="col-lg-4 control-label"><span class="required"></span>Número do Contrato:</label>
<div class="col-lg-5">
<input type="text" readonly="" placeholder="Número do Contrato" value="<?php echo $results[0]["numerocontrato"] ?>" id="numerocontrato" class="form-control" name="numerocontrato"><span class="error"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"><span class="required"></span>Responsável:</label>
<div class="col-lg-5">
<input type="text" readonly="" value="<?php echo $results[0]["nomecompleto"] ?>" placeholder="Responsável" id="nome_completo" class="form-control" name="nome_completo"><span class="error"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"><span class="required"></span>E-mail:</label>
<div class="col-lg-5">
<input type="text" readonly="" value="<?php echo $results[0]["email"] ?>" placeholder="E-mail" id="email" class="form-control" name="email"><span class="error"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"><span class="required"></span>Estado:</label>
<div class="col-lg-5">
<input type="text" readonly="" value="<?php echo $results[0]["estado"] ?>" placeholder="Estado" id="email" class="form-control" name="email"><span class="error"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"><span class="required"></span>Valor da Adesão:</label>
<div class="col-lg-5">
<input type="text" readonly="" value="<?php echo $results[0]["adesao"] ?>" placeholder="Adesão" id="adesao" class="form-control" name="adesao"><span class="error"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"><span class="required"></span>Valor Total:</label>
<div class="col-lg-5">
<input type="text" readonly="" value="<?php echo $results[0]["total"] ?>" placeholder="Total" id="total" class="form-control" name="total"><span class="error"></span>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<!-- DEPENDENTES -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Dependentes</h3>
</div>
<div class="panel-body">
<div class="col-lg-12" style="padding-left: 0; padding-right: 0;" >
<form action="index.php" method="get" >
<div class="col-lg-6 pull-left"style="padding-left: 0;" >
<span class="pull-left">
</div>
</form>
</div>
<div class="clearfix"></div>
<?php if ($results > 0) { ?>
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered ">
<tbody><tr>
<th>Nome do Dependente</th>
<th>CPF</th>
<th>Plano </th>
<th>Acomodação </th>
<th>Grau Parentesco </th>
<th>Valor do Dependente </th>
</tr>
<?php foreach ($results as $res) { ?>
<tr>
<td><?php echo $res["nomedependente"]; ?></td>
<td><?php echo $res["cpfdependente"]; ?></td>
<td><?php echo $res["planodependente"]; ?></td>
<td><?php echo $res["acomodacaodependente"]; ?></td>
<td><?php echo $res["grauparentescodependente"]; ?></td>
<td><?php echo $res["valordependente"]; ?></td>
</tr>
<?php } ?>
</tbody></table>
</div>
<?php } else { ?>
<div class="well well-lg"><b>Nenhum dependente encontrado.</b></div>
<?php } ?>
</div>
</div>
</div>
Enter the view code tbm
– rray
If I understand correctly you should do the search by contraction number and not by id. Your query by id returns how many records? tested it right in the bank?
– rray
by id returns me all results, and by numerocontrato also
– Mauro Santos
That one
id
is from the right dependent? what is the field that associates the dependent to the responsible? contract number?– rray
id is responsible, what associates the dependent is the contract number
– Mauro Santos
By the design of this table you can not do the search by id, you will have to search by numerocontrato. If you want to improve the system you can normalize the table, creating another table for the dependents, and link by the id of both tables.
– Guilherme Pressutto
You can create a person table to indicate if you are responsible or dependent
– Denis
Isn’t the spine wrong? Instead of SELECT * FROM registration WHERE 1 AND id = :numerocontrato, it should not be SELECT * FROM registration WHERE 1 AND numerocontrato?
– Tiago Gomes
Ta certo @Tiagogomes, I’m grabbing by id the contract number and trying to visualize the total number of dependents by the contract number
– Mauro Santos
Which select is correct what is separate or what is in the view?
– Tiago Gomes
I did the research on phpmyadmin and it’s giving me the correct values, but I don’t know what the problem is now that the result is not being viewed in view @Tiagogomes
– Mauro Santos
which result gives you when echo $sql; ?
– Tiago Gomes
SELECT * FROM cad_leadership WHERE numerocontrato = :numerocontrato @Tiagogomes
– Mauro Santos
Sorry. and echo $_GET["numerocontrato"]; and echo intval($_GET["numerocontrato"]);
– Tiago Gomes
should be the intval that should transfer 001 to 1 and so does not find any
– Tiago Gomes
Let’s go continue this discussion in chat.
– Mauro Santos
@Mauro Santos chat is no longer online. You can ask the question here :).
– Tiago Gomes