【发布时间】:2012-06-29 11:42:45
【问题描述】:
对于 JSON,我不知道自己在做什么。所以这可能是一个愚蠢的问题,我可能试图以一种奇怪的方式来做。任何帮助都会很棒。
我有这个 Jquery 日历,我想把它放在我的网站上。它允许 json_encode 日期。这是他们给出的例子。
$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 数据库来填充日历。这是我到目前为止所拥有的。它不起作用,我认为我对此并不聪明。
$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);
提前致谢!
【问题讨论】:
-
不应该 $dataSQL 变量首先作为 mysqli_query() 的参数吗?
-
不适用于这样的程序风格
标签: php mysql arrays json loops