簡體   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