我无法将此查询从Oracle数据库转换为PHP。
<input type="date" name="stardate" value="startdate" id="startdate" value="<?php echo isset($_GET["startdate"]);?>">
<input type="date" name="enddate" value="enddate" id="enddate" value="<?php echo isset($_GET["enddate"]);?>">
这是我的查询,它是正确的,但我不知道如何将它放入PHP:
SELECT *
FROM datepick
WHERE start_date not between to_date('03/28/2019','mm/dd/yyyy') and to_date('03/30/2019','mm/dd/yyyy')
and end_date not between to_date('03/28/2019','mm/dd/yyyy') and to_date('03/30/2019','mm/dd/yyyy');
发布于 2019-03-27 06:22:56
在表单提交之后,获取变量中的日期,并使用mysqli或pdo建立php-mysql连接,然后再使用连接,您可以将这些值传递给mysql查询。
<?php
// support you done form submit with get/post
$stardate = $_REQUEST['stardate']; // 03/28/2019
$enddate = $_REQUEST['enddate']; // 03/30/2019
// mysqli connection
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT * FROM datepick WHERE
start_date not between to_date('".$stardate."','mm/dd/yyyy') and to_date('".$enddate."','mm/dd/yyyy')
and end_date not between to_date('".$stardate."','mm/dd/yyyy') and to_date('".$enddate."','mm/dd/yyyy')";
$result=mysqli_query($con,$sql);
// Associative array
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
print_r ($row);
// check output and modify code accordingly
?>
https://stackoverflow.com/questions/55368991
复制相似问题