简体   繁体   中英

PHP mysql select date range not working

I use this code to get a data from a date range.But it only shows one row as result. mysql "Date" column uses the "Date" as datatype. Tell me what I'm doing wrong.

if(isset($_POST['from'])&& isset($_POST['to'])){
    include_once('../connection.php');
    echo $from= $_POST['from'];
      echo $to=$_POST['to'];
      $query_view="SELECT * FROM user_log where Date between '$from' and '$to'";
      $data_view=mysql_query($query_view,$connect);

.

while($row_view=mysql_fetch_array($data_view)){
    echo"
    <tr><td>".$row_view['User']."</td><td>".$row_view['Date']."</td><td>".$row_view['Time']."</td></tr>";
    }
    }

I think you want:

  echo $to=$_POST['to'];

instead of

  echo $to=$_POST['from'];

try this code

if(isset($_POST['from'])&& isset($_POST['to']))
{
     include_once('../connection.php');
     echo $from= $_POST['from'];
     echo $to=$_POST['to'];
     $query_view="SELECT * FROM user_log where `Date` between '".$from."' and '".$to."'";
     $data_view=mysql_query($query_view,$connect);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM