Field Search

1

Hi, I made a page that searches the products registered and then the results appear on the page resultados.php.

I would like the results.php page to be able to make a more exact query as soon as the lower price appears first, to have the option to choose the new or used product, to appear physical or legal person.

I put my code in pastebin: link

<?php include 'header.php'; ?>

<header class="docs-top">
    <div class="container docs-header">
   Todos os resultados
 </div>
</header>
<section>
  <div class="container">

    <?php 
    require 'conexao.php';

    $produto = $_POST['produto'];
    $sql = mysql_query("SELECT * FROM usuario where produto LIKE '%".$produto."%' ");

    // SELECT preco FROM usuario ORDER BY preco ASC

    $row = mysql_num_rows($sql);
    if ($row > 0) {
      while ($linha = mysql_fetch_array($sql)) {
        $produto = $linha['produto'];
        $bairro = $linha['bairro'];
        $preco = $linha['preco'];
        $telefone = $linha['telefone'];
        $nome = $linha['nome'];
        $estado = $linha['estado'];
      }
    } else {
      echo "Nenhum resultado encontrado";
    }
    ?>


    <div class="well recomentadion clearfix">
      <h1>Pesquisar</h1>
      <form action="" method="POST">     
        <fieldset>
          <div class="form-group col-md-3">
            <label class="" for="advertisement">Título do Anúncio </label>                
            <div class="control mr-30">
              <input type="text" id="title" name="title" class="form-control" value="" placeholder="Título" data-original-title="" title="">
            </div>
          </div>                  

          <div class="form-group col-md-3">
            <label class="" for="advertisement">Novo/Usado</label>                
            <div class="control mr-30">
              <select class="form-control">                               
                <option>Novo</option>
                <option>Usado</option>
              </select> 
            </div>
          </div>

          <div class="form-group col-md-3">
            <label class="" for="advertisement">Empresa/P. fisica</label>                
            <div class="control mr-30">
             <select class="form-control">
              <option>Todos</option>
              <option>Empresa</option>
              <option>Pessoa fisica</option>
            </select> 
          </div>
        </div>

        <div class="form-group col-md-3">
          <label class="" for="advertisement">Ordernar por Preço</label>                
          <div class="control mr-30">
            <select class="form-control">
              <option>Menor preço</option>
              <option>Maior preço</option>                               
            </select>  
          </div>
        </div>  

        <div class="clear"></div> 
        <input type="submit" style="margin-top:20px;" name="submit" class="btn btn-primary pull-right" value="Pesquisar"> 
      </fieldset>
    </form>
  </div>

  <!-- produto -->

  <div class="bs-docs-example">
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td align="center">:<img src="http://wcloudstatic.s3.amazonaws.com/img/no_image.jpeg"width="150" height="150" /></td>                 
          <td><?php echo ".$produto"; ?> <br><br> <?php echo ".$bairro"; ?> - <?php echo ".$estado"; ?><br> <?php echo ".$nome"; ?> - <?php echo ".$telefone"; ?></td>
          <td><?php echo ".$preco"; ?></td>
        </tr>          
      </tbody>
    </table>    
  </div>

  <!-- /produto -->

</div>

</section>

<?php include 'footer.php'; ?>
    
asked by anonymous 11.09.2015 / 07:21

1 answer

0

Do you want to get the product in the user table? You have to correctly model the database to better implement the querys.

You did the correct query structure to display the product and did not do it with the price. Just a little attention.

Following your example, I'll put everything into a query.

$sql = mysql_query("SELECT * FROM usuario where produto LIKE '%".$produto."%' order by preco asc");

$row = mysql_num_rows($sql);
if ($row > 0) {

  while ($linha = mysql_fetch_array($sql)) {
    $produto = $linha['produto'];
    $bairro = $linha['bairro'];
    $preco = $linha['preco'];
    $telefone = $linha['telefone'];
    $nome = $linha['nome'];
    $estado = $linha['estado'];
  }

} else {
  echo "Nenhum resultado encontrado";
}
?>

Or you can use paginator to choose the view, by price, product, individual or legal entity, etc.

I recommend studying the table relationships and their keys.

    
11.09.2015 / 15:01