List and search records

Asked

Viewed 47 times

0

Good afternoon, guys. I’d like your help if I could. I’m already racking my brain and I still can’t find the right solution. Please if anyone can help I really appreciate.

  • 3 linked tables
    1. repestado | id, nome, Uf
    2. repregiao | id, est_id, titulo
    3. Representatives | id,

I have a select referring to table respected, when selecting a state, you should list all the records in the table REPRESENTATIVES who has the field EST_ID equal to the field id table STATES..

PROBLEM: in my query this listing all representatives that have the est_id equal to the id of the state table, however where this 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 only show the exact record to my search, not other variable.

FOLLOWS 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&atilde;o de Atua&ccedil;&atilde;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>
  • Why don’t you use field = '".$_POST['est_id']."' instead of field like '".$_POST['est_id']."%' ?

  • Even so it doesn’t work, keeps giving error, different that now listed nothing.

  • What value are you sending in $_POST'est_id'] and which field values field?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.