這裏是sql查詢,它在phpmyadmin上測試時工作正常。 下面是截圖。查詢返回空的結果在PHP中,但工作正常否則
下面是PHP代碼和它
<?php
header('Content-type=application/json;charset=utf-8');
include("connection.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$event_date1= mysqli_real_escape_string($con,$_POST['event_date1']);
$event_date2= mysqli_real_escape_string($con,$_POST['event_date2']);
$query = ("SELECT topic1 as topic from feedbackform_db where topic1 is not null AND event_date between $event_date1 AND $event_date2
union SELECT topic2 as topic from feedbackform_db where topic2 is not null AND event_date between $event_date1 AND $event_date2
union SELECT topic3 as topic from feedbackform_db where topic3 is not null AND event_date between $event_date1 AND $event_date2
union SELECT topic4 as topic from feedbackform_db where topic4 is not null AND event_date between $event_date1 AND $event_date2
union SELECT topic5 as topic from feedbackform_db where topic5 is not null AND event_date between $event_date1 AND $event_date2
union SELECT topic6 as topic from feedbackform_db where topic6 is not null AND event_date between $event_date1 AND $event_date2
union SELECT topic7 as topic from feedbackform_db where topic7 is not null AND event_date between $event_date1 AND $event_date2
union SELECT topic8 as topic from feedbackform_db where topic8 is not null AND event_date between $event_date1 AND $event_date2 ");
$response=mysqli_query($con,$query);
if($response)
echo "true";
else
echo "false";
// set array
$array = array();
// look through query
while($row = mysqli_fetch_assoc($response))
{
// add each row returned into an array
$array[] = $row;
// OR just echo the data:
echo $row['topic']; // etc
}
$data['details']=$array;
echo json_encode($data);
print_r($array);
// echo json_encode($array);
}
mysqli_close($con);
?>
<html>
<head>
<title>client welcome Page</title>
<style type = "text/css">
body \{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
\}
label \{
font-weight:bold;
width:100px;
font-size:14px;
\}
.box \{
border:#666666 solid 1px;
\}
</style>
</head>
<body bgcolor = "#FFFFFF">
<div align = "center">
<div style = "width:300px; border: solid 1px #333333; " align = "left">
<div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
<div style = "margin:30px">
<form action = "" method = "post">
<label>event_date1:</label><input type = "text" name = "event_date1" class = "box" /><br/><br />
<label>event_date2:</label><input type = "text" name = "event_date2" class = "box" /><br/><br />
<input type = "submit" value = " Submit "/><br />
</form>
<div style = "font-size:11px; color:#cc0000; margin-top:10px"></div>
</div>
</div>
</div>
</body>
</html>
當我在localhost.Result運行此HTML表單是空的,沒有錯誤。 但查詢運行它的表現「真」爲響應變量
這是結果
真{「細節」:[]}陣列()
爲什麼我在沒有得到值數組?
檢查什麼是呼叫的MySQL前的'$ query'值。 – Alex
空結果集不是錯誤。這是恰好不包含行的完美有效結果。你需要檢查mysqli_num_rows()來查看你匹配了多少行,這無疑會回到'0',留下一個空數組。 –
確保您獲得活動日期值? –