我正在编写一个从数据库中获取数据并显示它的脚本在每个页面上只显示特定日期的数据,该日期由html输入表单定义。查看代码。
}else{
//date selector - this chooses which date to display the data. The output of this needs to
be what date the data is sorted by.
$date = date('Y-m-d');
echo "
<input type='date' name='date' value='$date'>";
//include the database connection so you can fetch data from the table 'notices'
include("db.php");
//sql fetching data from the database ad displaying it
//Each row of data is currently sorted by the field id, which is currently auto-incrementing
$sql = "SELECT * FROM notices ORDER BY id DESC";
$stmt = $db->query($sql);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0){
while($row = $stmt->fetch()){
echo "
<p><b>".$row['subject']."</b></p>
<p>".$row['message']."</p>
<p>".$row['name']."<br></p>
<hr>
";
}
}
}
任何帮助都将不胜感激。谢谢
您可以使用mysqli查询来显示数据库中的数据,这是一个类似的简单代码
if ($result = mysqli_query($link, "SELECT date FROM database where date = your html form input date")) {
printf("Select returned %d rows.'n", mysqli_num_rows($result));
/* free result set */
mysqli_free_result($result);
}