Good afternoon, guys. if it is possible I would like your help .. I am already breaking my mind and still can not find a correct solution. Please if anyone can help thank you very much.
- 3 linked tables
- reset | id, name, uf
- repregiao | id, est_id, title
- Representatives | id,
I have a select referring to the repesting table, when selecting a state, should list all the records in the REPRESENTATIVES table that has the EST_ID equal to the id field of the STATES table.
PROBLEM: in my query this is listing all the representatives that have the est_id equal to the id of the state table, but where it repeats shows equal
Example States: Alagoas = ID 2 Representatives: A = est_id 2 / B = est_id 22 / c = est_id 12 the query is showing the 3 combinations where the 2 repeats, and I need to only show the exact records to my search, not other variable.
FOLLOW THE CODE -
<div class="fullwidthbanner-subpage-container img-slide img-sub-01">
<div class="parallax-slider">
<div class="container">
<div class="slide">
<h1>Representantes</h1>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<!-- /fullwidthbanner-container -->
<div class="container content page">
<div class="row mobile-spacing-5">
<div class="row">
<div class="span12">
<div class="page-header arrow-grey">
<h2>Selecione o estado requerido</h2>
</div>
</div>
<style>
.custom-select-menu{ width: 300px; background: #fff; border: #ccc; float: left}
.custom-select-menu > ul {height: 200px;overflow-y: scroll;}
</style>
<div class="span4">
<form class="navbar-form" method="post" action="">
<div class="subscribe-form " >
<select name="est_id" class="custom-select-menu">
<option value="">Seleciones um Estado...</option>
<?php
$query = mysqli_query($_mysqli, "select * from repestado order by nome desc");
while ($categoria = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
?>
<option value="<?php echo $categoria['id']; ?>"><?php echo $categoria['nome']; ?></option>
<?php
}
?>
</select>
</div>
<button id="contact-submit" type="submit" class="btn btn-green ">Buscar</button>
</form>
</div>
<div class="span6">
<p>
<div class="span3 ">
<div class="row">
<?php
if (empty($_POST['est_id'])) {
$query = mysqli_query($_mysqli, "select r.id, r.contato rep_contato, r.empresa rep_empresa, r.telefone rep_telefone, r.email rep_email, g.titulo reg_titulo, e.nome est_nome from representantes r inner join repregiao g on r.reg_id = g.id inner join repestado e on r.est_id = e.id order by r.id desc");
} else {
$query = mysqli_query($_mysqli, "select r.id, r.contato rep_contato, r.empresa rep_empresa, r.telefone rep_telefone, r.email rep_email, g.titulo reg_titulo, e.nome est_nome from representantes r inner join repregiao g on r.reg_id = g.id inner join repestado e on r.est_id = e.id where e.id field like '".$_POST['est_id']."%' order by e.id desc");
}
$resultado = mysqli_num_rows($query);
if ($resultado > 1) {
while ($rest = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
?>
<div class="span8">
<div class="twitter-item">
<ul class="tweet_list">
<li class="tweet_first tweet_odd">
<span class="tweet_text">Região de Atuação: <?php echo $rest['reg_titulo'] ?> | <?php echo $rest['est_nome'] ?></span></br>
<span class="tweet_text">Empresa: <?php echo $rest['rep_empresa'] ?></span></br>
<span class="tweet_text">Contato: <?php echo $rest['rep_contato'] ?></span></br>
<span class="tweet_text">Telefone:<?php echo $rest['rep_telefone'] ?></span></br>
<span class="tweet_text">Email: <?php echo $rest['rep_email'] ?></span></br>
</li>
</ul>
</div>
</div>
<?php
}
} else {
?>
<div class="span8">
<div class="twitter-item">
<ul class="tweet_list">
<li class="tweet_first tweet_odd">
<h5>Não temos representantes nesse estado.</h5></br>
<span class="tweet_text">Quer ser nosso representante?</span></br>
<span class="tweet_text">Clique no botão enviar e encaminhe seus dados completos através do e-mail e aguarde que faremos contato.</span></br>
<a class="btn btn-green" href="mailto:[email protected]">Enviar Dados</a>
</li>
</ul>
</div>
</div>
<?php
}
?>
</div>
</div>
</p>
</div>
</div>
</div>
</div>