如何将数组与 sql 查询一起使用,然后循环遍历结果?
这是我所拥有的,但我不确定我应该如何在查询中使用内爆变量
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<titleard Log</title>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function() { new JsDatePick({ useMode:2, target:"inputField", dateFormat:"%d-%m-%Y" }); new JsDatePick({ useMode:2, target:"inputField2", dateFormat:"%d-%m-%Y" }); };
</script>
</head>
<body>
<form action="#" method="post">
<input type="checkbox" name="driver[]" value="Julia">Julia
<input type="checkbox" name="driver[]" value="Pete">Pete From
<input type="text" name="date1" size="12" id="inputField" /> To
<input type="text" name="date2" size="12" id="inputField2" />
<input type="submit" value="Submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit']) && ($_POST['submit'] == "Submit"))
{
$date1 = $_POST['date1'];
$date2 = $_POST['date2'];
$date1 = date("Ymd", strtotime($date1));
$date2 = date("Ymd", strtotime($date2));
$drivers = "'".implode("','",$_POST['driver'])."'";
}
$mysqli = new mysqli('' );
if($mysqli->connect_error)
echo {
die("$mysqli->connect_errno: $mysqli->connect
_error");
}
$query = "SELECT * FROM wizardlog WHERE driver IN (?) AND date between ? and ? ";
$stmt = $mysqli->stmt_init();
if(!$stmt->prepare($query))
{
print "Failed to prepare statement\n";
}
else
{
$stmt->bind_param("sss", $drivers, $date1, $date2);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{
foreach($rows as $row)
{
$id = $row['id'];
$driver = $row['driver'];
$date = date("d/m/y", strtotime($date));
$time = $row['time'];
$time = substr($time, 0, 5);
$fname = $row['fname'];
$lname = $row['lname'];
$town = $row['town'];
任何帮助将不胜感激!