繁体   English   中英

PHP datepicker日历

[英]PHP datepicker calendar

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

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>";
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM