下面给出的PHP函数显示加载页面的最新插入,但我想在每次插入行时刷新数据。我听说过ajax,但我不是很熟悉它。谁能给我一些指导?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="OPlayout.css"/>
<title>Operator View</title>
</head>
<body>
<div id="whole">
<section id="mid_section"></br>
<h2>Requests</h2></br>
<?php include 'functions.php';
currentRequests();
?>
</section>
</div>
</body>
</html>
PHP功能:
function currentRequests(){
//Include database connection file
include 'databaseConnect.php';
//Call global function to connect to db
$connection = connectToDatabase();
$queryToRun = "SELECT * FROM table_user_request
WHERE 1=1
AND date(entry_date) = date(now())
ORDER BY entry_date DESC";
$result = mysqli_query($connection, $queryToRun);
//Create a table to store the results
echo "<table border = '1' style='max-width:1180px;font-size: 14px;' >
<tr>
<td style='width:120px '>Name</td>
<td style='width:120px '>Location</td>
<td style='width: 20px '># of Riders</td>
<td style='width:120px '>Destination</td>
<td style='width:150px '>Email</td>
<td style='width:100px '>Telephone</td>
<td style='width:50px '>Date</td>
<td style='width:50px '>Status</td>
<td style='width: 60px '>Vehicle</td>
<td style='width:50px '>Cancellation Reason</td>
<td style='width: 60px '>Priority</td>
</tr>";
//Print records until done
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
//echo("<table border = '1' style='width:1200px'>");
//Output results found in the database
echo("<tr>
<td>" . $row['1']
. "</td> <td>" . $row['3']
. "</td> <td>" . $row['5']
. "</td> <td>" . $row['4']
. "</td> <td>" . $row['8']
. "</td> <td>" . $row['9']
. "</td> <td>" . $row['10']
. "</td> <td>" . $row['11']
. "</td> <td>" . $row['12']
. "</td> <td>" . $row['13']
. "</td> <td>" . $row['14'] . "</td>
</tr>");
}
echo("</table>");
}
答案 0 :(得分:0)
快速提示:您的SQL中不需要1=1
,它将默认获取所有可能的行。我很确定如果您正确设置了列数据类型,则无需转换date()
。
SELECT * FROM table_user_request
WHERE date(entry_date) = date(now())
ORDER BY entry_date DESC
我不确定问题是什么,你想要加载行之间的延迟吗?刷新数据是什么意思? Ajax会为您做什么是允许动态加载数据而不重新加载页面。