我正在编写一个从数据库中获取数据并显示它的脚本。我需要它 仅显示每页上某个日期的数据,即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>
";
}
}
}
任何帮助都将非常感激。感谢。
答案 0 :(得分:0)
你可以使用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);
}