Select date before searching

0

I've tried to do a lot of things but none of them worked out, ok let's go.

I need to do a filter by date to make searching easier, even setting a specific date ends up showing all the results, I want to get a timestamp date, and I I'm using datepicker to set the values, I'm probably not doing it right.

Here is my code:

<?php

if(isset($_GET['submit'])){

// conexao
$db_host="localhost";
$db_username="";
$db_password="";
$db_name="";
$tabela="usuario";
$BDcoluna1="log";
$BDcoluna2="nome";
$BDcoluna3="usuario";
$BDcoluna4="email";

      mysql_connect("$db_host","$db_username","$db_password");
      mysql_select_db("$db_name");

      $query=mysql_real_escape_string($_GET['query']);

       $query_for_result=mysql_query("
            SELECT * FROM $tabela WHERE
            $BDcoluna1 BETWEEN '".$de."%' AND '".$para."%'
            AND
            $BDcoluna2 LIKE '".$query."%'
            OR
            $BDcoluna3 LIKE '".$query."%'
            OR
            $BDcoluna4 LIKE '".$query."%'
            ");
echo "<center>
<table border='1' cellpadding='5' cellspacing=0 style=border-collapse: collapse bordercolor='#4B5AAB'>";
echo "<tr> <th>Data</th>
                <th>Analista</th>
                    <th>Solicitante</th>
                <th>Centro de Custo</th>
           <th>motivos</th>
      </tr>";
echo "<h2>Resultado da Busca</h2>";

while($data_fetch=mysql_fetch_array($query_for_result))
{   echo "<tr>";
echo '<td>' .substr($data_fetch[$BDcoluna1]. '</td>', 0,160);
echo '<td>' .substr($data_fetch[$BDcoluna2]. '</td>', 0,160);
echo '<td>' .substr($data_fetch[$BDcoluna3]. '</td>', 0,160);
echo '<td>' .substr($data_fetch[$BDcoluna4]. '</td>', 0,160);
echo "</tr>";
}
mysql_close();
}
?>
    
asked by anonymous 11.11.2014 / 12:36

1 answer

1

The problem is in your query.

$query_for_result=mysql_query("
        SELECT * FROM $tabela WHERE
        $BDcoluna1 BETWEEN '".$de."%' AND '".$para."%'
        AND
        $BDcoluna2 LIKE '".$query."%'
        OR
        $BDcoluna3 LIKE '".$query."%'
        OR
        $BDcoluna4 LIKE '".$query."%'
        ");

Try to enter your OR condition in parentheses:

$query_for_result=mysql_query("
    SELECT * FROM {$tabela} WHERE
    $BDcoluna1 BETWEEN '{$de}' AND '{$para}'
    AND (
        $BDcoluna2 LIKE '{$query}%' OR 
        $BDcoluna3 LIKE '{$query}%' OR 
        $BDcoluna4 LIKE '{$query}%' 
    )
");
    
11.11.2014 / 18:26