javascript - 如何在 jQuery/JavaScript Bootstrap 中插入 PHP 变量?

标签 javascript php jquery twitter-bootstrap

所以这是我第一次尝试使用 Bootstrap ,我尝试在 Bootstrap 中使用“chart_filled_blue”,但我遇到了问题,包括 Bootstrap 的 jquery 中的 php 结果,我将非常感谢任何帮助或建议。

我的基本 pdo select 可以获取 View /日期

$sth = $db->prepare("SELECT date, views FROM views_by_date");
    $sth->execute();

    $result = $sth->fetchAll();
    print_r($result);

我将限制选择,因此它只会获取最后 6 或 7 行

所以现在我的chart_filled_blue.js是这样的

"use strict";

$(document).ready(function(){

    // Sample Data
    var d1 = [[1262304000000, 0], [1264982400000, 500], [1267401600000, 700], [1270080000000, 1300], [1272672000000, 2600], [1275350400000, 1300], [1277942400000, 1700], [1280620800000, 1300], [1283299200000, 1500], [1285891200000, 2000], [1288569600000, 1500], [1291161600000, 1200]];

    var data1 = [
        { label: "Total clicks", data: d1, color: App.getLayoutColorCode('blue') }
    ];

    $.plot("#chart_filled_blue", data1, $.extend(true, {}, Plugins.getFlotDefaults(), {
        xaxis: {
            min: (new Date(2009, 12, 1)).getTime(),
            max: (new Date(2010, 11, 2)).getTime(),
            mode: "time",
            tickSize: [1, "month"],
            monthNames: ["Jan", "FebBBBB", "Mar", "Apr", "May", "June", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
            tickLength: 0
        },
        series: {
            lines: {
                fill: true,
                lineWidth: 1.5
            },
            points: {
                show: true,
                radius: 2.5,
                lineWidth: 1.1
            },
            grow: { active: true, growings:[ { stepMode: "maximum" } ] }
        },
        grid: {
            hoverable: true,
            clickable: true
        },
        tooltip: true,
        tooltipOpts: {
            content: '%s: %y'
        }
    }));


});

我想将所有 var d1 替换为数据库中的 View ,然后将月份名称替换为数据库中的日期

最好的方法是什么?

最佳答案

您可以将 d1 替换为 <?php echo $result['view'];?>

关于javascript - 如何在 jQuery/JavaScript Bootstrap 中插入 PHP 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28856420/

相关文章:

php - Laravel Sender 或 From 未按预期工作

javascript - 禁用链接和 <abbr> 上的浏览​​器工具提示

javascript - 随机 css 属性对每个框应用不同的数字

javascript - AngularJS 服务中的 JSDoc

javascript - ASP.NET MVC - 将包含数组的 FormData 映射到模型类

javascript - 在 Dropzonejs 中调用 .processQueue() 时出错

javascript : post data after click finished

php - 对我在用 PHP 运行的 Web 服务器中缓冲数据有什么建议吗?

php - 使用 TCPDF 将 CMYK 图像变为负片

javascript - 将代码荧光笔应用于 Textarea