json_en code()数组中while循环对于MySQL日历

问题描述:

我不知道,当涉及到JSON我在做什么。所以这可能是一个愚蠢的问题,我可能会尝试做它一个奇怪的方式。任何帮助将是巨大的。

I do not know what I am doing when it comes to JSON. So this may be a stupid question and I may be trying to do it a weird way. Any help would be great.

我有这个jQuery日历我试图把我的网站上。它允许json_en code的日期。这里是他们给的例子。

I have this Jquery Calendar I am trying to put on my website. It allows for json_encode for dates. Here is the example they gave.

    $year = date('Y');
$month = date('m');

echo json_encode(array(

    array(
        'id' => 111,
        'title' => "Event1",
        'start' => "$year-$month-10",
        'url' => "http://yahoo.com/"
    ),

    array(
        'id' => 222,
        'title' => "Event2",
        'start' => "$year-$month-20",
        'end' => "$year-$month-22",
        'url' => "http://yahoo.com/"
    )

));

我要使用现有的MySQL数据库来填充日历。这里是我到目前为止所。它不工作,我不认为我是聪明与此有关。

I want to use an existing mySQL database to populate the calendar. Here is what I have so far. It isn't working and I don't think I am being intelligent with this.

$dataSQL ="select *
            FROM events
        ";

$dataResult = mysqli_query($dataBase, $dataSQL);

$encode = array();

$p=0;
    while($allRow = mysqli_fetch_array($dataResult))
        {
            $new = array(
                        'id' => "$allRow['id']",
                        'title' => "$allRow['title']",
                        'start' => "$allRow['date']",
                        'url' => "$allRow['url']"
                    );
            array_splice($encode, ($p), 0, $new);

            $p++;
        }


echo json_encode($encode);

在此先感谢!

如果你只是有你的阵列结构的问题,你已经走了一个有点复杂。你可以建立一个数组是这样的:

If you're just having problems with your array structure, you've gone a bit complex. You can build an array like this:

$encode = array();

while($allRow = mysqli_fetch_array($dataResult))
       {
            $new = array(
                        'id' => $allRow['id'],
                        'title' => $allRow['title'],
                        'start' => $allRow['date'],
                        'url' => $allRow['url']
                    );
            $encode[] = $new;

        }

echo json_encode($encode);