PHP 日期选择器日历


PHP datepicker calendar

首先,让我告诉你我想做什么。我正在尝试做一个日期选择器,当用户单击日期时,将显示有关特定日期的信息。

日历.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Datepicker - Default functionality</title>
    <link rel="stylesheet" href="jquery-ui.css">
    <link rel="stylesheet" href="jquery-ui.min.css">
    <link rel="stylesheet" href="jquery-ui.structure.css">
    <link rel="stylesheet" href="jquery-ui.structure.min.css">
    <link rel="stylesheet" href="jquery-ui.theme.css">
    <link rel="stylesheet" href="jquery-ui.theme.min.css">
    <script src="jquery.js"></script>
    <script src="jquery-ui.js"></script>
    <script src="jquery-ui.min.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
    $( "#datepicker" ).datepicker({
        minDate: 0, 
        maxDate: 30, //The maximal date that can be selected, i.e. + 1 month, 1 week, and 3 days from "now"
        showAnim: "bounce",
        onSelect: function(dateText, inst) {
            $.ajax({
                type: 'POST',
                url: 'my_ajax_stuff.php',
                data: {date : dateText},
                success: function(response){
                    document.getElementById("in").innerHTML = response;
                }
            });
        }
    });
    </script>
</head>
<body>
    <p>Date: <input type="text" id="datepicker"></p>
</body>
</html>

这是我的my_ajax_stuff.php

<?php
$connection = mysqli_connect("localhost","root","","test");
if (!$con) {
    die('Could not connect: ' . mysqli_error($connection));
}
$sql = "SELECT * FROM calendar WHERE startdate={$_post['dateText']}";
$result = mysqli_query($connection,$sql);
echo "<table>
<tr>
<th>title</th>
<th>startdate</th>
<th>enddate</th>
</tr>
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['title'] . "</td>";
    echo "<td>" . $row['startdate'] . "</td>";
    echo "<td>" . $row['enddate'] . "</td>";
    echo "</tr>";
}
echo "</table>";

mysqli_close($connection);
?>

现在的问题是,日期选择器似乎看起来很好。但是当我单击日期时,没有显示任何数据。我有一种感觉,是我的php导致了问题。如果有人能给我一些关于我应该如何写它的方向......我真的很棒。非常感谢。

仔细观察你的PHP代码,你应该能够在第一个回显之后发现缺少的双引号。这是一个更正后的版本,可以帮助您继续前进。

<?php
$connection = mysqli_connect("localhost","root","","test");
if (!$con) {
    die('Could not connect: ' . mysqli_error($connection));
}
$sql = "SELECT * FROM calendar WHERE startdate={$_post['dateText']}";
$result = mysqli_query($connection,$sql);
echo "<table>
<tr>
<th>title</th>
<th>startdate</th>
<th>enddate</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['title'] . "</td>";
    echo "<td>" . $row['startdate'] . "</td>";
    echo "<td>" . $row['enddate'] . "</td>";
    echo "</tr>";
}
echo "</table>";
?>