2016-03-13 74 views
1

我试图获取从数据库事件到日历,但在这个阶段,它只是输出它的数据库和JSON获得的第一个事件时,我赞同它,它只是返回的第一个事件完整的日历刚刚得到的第一个事件

<?php 
include("dbcon.php"); 

$events1 = array(); 

$sql345="select * from takimet"; 
$result = mysql_query($sql345)or die(mysql_error()); 

while ($row=mysql_fetch_array($result)){    
    $id = $row['agent_id']; 
    $title = $row['ezitimi']; 
    $start = $row['datestamp']; 

    $events1 = array(
     'id' => "$id", 
     'title' => "$title", 
     'start' => "$start" 
    ); 

} 
echo json_encode($events1); 
?> 
+0

它仍然在日历仅输出所述第一事件在这里是其中i取JSON –

+0

事件:;, 编辑[]:真, droppable:true, –

+0

请不要使用[mysql_'数据库扩展](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php),它 是弃用(一去不复返在PHP7) 特别是如果你刚开始学习PHP,花你的精力学习'PDO'或'mysqli_'数据库扩展, [这里是一些帮助来决定使用哪一种(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – RiggsFolly

回答

1

你每次都在写循环的同一个数组。

相反

$events1 = array(); 

while ($row=mysql_fetch_array($result)){    

    $events1[] = array(     //<--- changed 
         'id' => $row['agent_id'], 
         'title' => $row['ezitimi'], 
         'start' => $row['datestamp'] 
        ); 

} 
+0

TY这个问题不相关的,但现在它不输出在所有 –

+0

还好事件的日历中,但现在即时得到一个奇怪的输出,当我按下日历03月06日€” 12年,2016年 –

+0

周正如那句老话,你只能得到了你放什么。这看起来像一个UTF8问题。 – RiggsFolly