0

MySQL データベースのイベントを完全なカレンダーで表示しようとしています。これが私のコード、json-events.php です:

   @mysql_connect($host,$user,$pass)
    or die("Impossible de se connecter ! Vérifier le nom du serveur, le login ou le mot de passe !");

@mysql_select_db("$bdd")
    or die ("Impossible de trouver la base de données !");  



$req_lire ="SELECT idfiches,titrefiches,DATE_FORMAT(fiches.rvfiches, '%Y-%m-%d') as startdate FROM fiches"; 

    $lire2 = mysql_query($req_lire) or die($req_lire."<br>\n".mysql_error());

 $events = array();
    while ($reponse = mysql_fetch_array($lire2))
{
$id = $reponse['idfiches'];
$title = $reponse['titrefiches'];
$start = $reponse['startdate'];

$events = array(
            'id' => "$id",
            'title' => "$title",
            'start' => "$start"
            );
}
echo json_encode($events);

何も表示されず、エラーもありません。単一のファイルでリクエストを試すと、問題ありません。私たちを手伝ってくれますか?

4

1 に答える 1

0

まず、$events配列を最後の反復で取得したものに置き換えます。

これを更新してみてください:

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

これに:

$events[] = array(
        'id' => "$id",
        'title' => "$title",
        'start' => "$start"
        );

そうすれば、各反復のデータを$events配列に追加することになります。

于 2012-11-16T16:37:17.117 に答える