1

I'm trying to fetch events from database to calendar but at this stage it just outputs the first event it gets from the database and the json when i echo it it returns just the first event

<?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);
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Henri Sula
  • 41
  • 6
  • still it outputs only the first event in calendar here is where i fetch the json – Henri Sula Mar 13 '16 at 18:28
  • events:[ ], editable: true, droppable: true, – Henri Sula Mar 13 '16 at 18:28
  • Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Especially if you are just learning PHP, spend your energies learning the `PDO` or `mysqli_` database extensions, [and here is some help to decide which to use](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – RiggsFolly Mar 13 '16 at 18:30
  • i know man but im using php 5.5 anyway and im very familiar to mysql_ its a bit hard upgrading to mysqli or pdo – Henri Sula Mar 13 '16 at 18:32
  • this problem is not related to mysql_ though – Henri Sula Mar 13 '16 at 18:32

1 Answers1

1

You are over writing the same array occurance each time round you loop.

Instead

$events1 = array();

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

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

}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149