我正在尝试在两个日期之间获取数据。我从我的数据库中获取数据。问题是submit_date1列不在我的数据库中,所以我将submit_date和submit_date1数据存储在同一个变量中。然后尝试获取数据。
$submit_date = isset($_REQUEST['submit_date']) ? $_REQUEST['submit_date'] : '';
$submit_date1 = isset($_REQUEST['submit_date1']) ? $_REQUEST['submit_date1'] : '';
$date2 = date('Y-m-d',strtotime($submit_date));
$date2 = date('Y-m-d',strtotime($submit_date1));
$user1 = $wpdb->get_results("select * from diary_user_form_storage where category_name='delivery_form' AND DATE(submit_date) <='".$date2."' AND DATE(submit_date) >= '".$date2."'");
[enter image description here][1]
[1]:
答案 0 :(得分:0)
嗨,这是这个问题的答案。谢谢大家。
$submit_date = isset($_REQUEST['submit_date']) ? $_REQUEST['submit_date'] : '';
$submit_date1 = isset($_REQUEST['submit_date1']) ? $_REQUEST['submit_date1'] : '';
$date3 = date('Y-m-d',strtotime($submit_date1));
$date2 = date('Y-m-d',strtotime($submit_date));
$user1 = $wpdb->get_results("select * from diary_user_form_storage where category_name='delivery_form' AND DATE(submit_date) >='$date3' AND DATE(submit_date)<= '$date2'");
答案 1 :(得分:0)
我认为这会对你有所帮助。 从PHP中的两个日期之间的MYSQL表中获取结果。试试这段代码:
<?php
$con=mysqli_connect("localhost","root","","database_name");
$first_date=$_POST["first_date"];
$second_date=$_POST["second_date"];
$sql=mysqli_query($con,"SELECT * FROM `table_name` WHERE `date` BETWEEN '".$first_date."' AND '".$second_date."' ");
?>