【问题标题】:Fetch Json from MySQL in Jquery calender在 Jquery 日历中从 MySQL 获取 Json
【发布时间】:2018-06-25 04:55:16
【问题描述】:

我的 DB>test (Table) 中有 JSON 格式的数据

   [{
    "day": 0,
    "periods": []
}, {
    "day": 1,
    "periods": [{
        "start": "01:45",
        "end": "07:45",
        "title": ""
    }]
}, {
    "day": 2,
    "periods": [{
        "start": "02:45",
        "end": "07:45",
        "title": ""
    }]
}, {
    "day": 3,
    "periods": [{
        "start": "01:45",
        "end": "07:15",
        "title": ""
    }]
}, {
    "day": 4,
    "periods": [{
        "start": "04:45",
        "end": "09:45",
        "title": ""
    }]
}, {
    "day": 5,
    "periods": []
}, {
    "day": 6,
    "periods": []
}]

我想在 Jquery 调度程序中获取它,如下所示:

<script>
$(function () {
  $("#schedule3").jqs({ 

  });
</script>

我的问题是我无法获取 mySQL 数据库中保存的 json 值并将其显示在 jQuery 调度程序上。image 下面是我的 import.php 代码:

$selected = mysqli_select_db($conn,"db") 
$fetch_port_relation = "SELECT * FROM `test`";
$result_port_relation = $conn->query($fetch_port_relation);
if ($result_port_relation->num_rows > 0) {
// output data of each row
while($ios_row = $result_port_relation->fetch_assoc()) {
    $data = $ios_row['test'];
    $jsondata = json_decode($data);
    $jsondata->day; //this returns
    print_r($data);
    foreach($jsondata->periods as $periods) {
    echo $periods->start;

【问题讨论】:

  • 你的问题到底是什么?
  • 你需要解释更多。你有什么问题,你尝试了什么,你在哪里卡住了?
  • 嗨,Alex,我被困在从 mySQL 获取 json 数据(我能够获取它但无法解码)并在 jQuery 每周调度程序脚本的前端获取它。跨度>

标签: php jquery mysql json


【解决方案1】:

取决于您使用的编程语言,如果您使用的是 Java/php,请创建一个服务方法,该方法将从数据库中获取 JSON 并通过 ajax 返回 JSONobject,并通过 jquery javascript 将其引入日历。

我还建议您使用完整的日历,因为它很容易掌握。

$('#calendar').fullCalendar({

    eventSources: [

        // your event source
        {
            url: '/myfeed.php', // use the `url` property
            color: 'yellow',    // an option!
            textColor: 'black'  // an option!
        }

        // any other sources...

    ]
});

我的 Feed 会返回 json 对象。

【讨论】:

  • 您好 Farhan,感谢您的回复。我只需要每周调度程序,我不需要日历中的月份和年份,我检查了完整的日历并且知道如何开始。你能建议吗
  • 是的,您可以使用完整日历的每周视图,fullcalendar.io/docs/usage 这是让您从基本层面开始的链接,它有每周视图、每日视图、点击事件选项等等。如果您需要特定级别的帮助,请随时问我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-23
  • 2015-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-18
相关资源
最近更新 更多