如何使用(PHP)foreach用我的数据库中的记录更新我的javascript时间表?

I am making a timetable with php and javascript and if each time i add a (name,time,date..) i want to update my javascript timetable

i am using phpmyadmin for my database and the timetable is gantt and from am4charts

this is the php:

$query =  "SELECT Nom FROM registre";
$resultat = mysqli_query($connect, $query);
$data = array();
//$chart_data = '';
//while ($row = mysqli_fetch_array($resultat)) 
if(mysqli_num_rows($resultat)>0){
  while ($row = mysqli_fetch_assoc($resultat))    
{
    $data2[] = $row;
}

}

//print_r($data);

foreach ($data2[0] as $data2) {
  echo $data2;
}

this is javascript:

chart.data = [
{
name:"<?php echo $data2; ?>",
fromDate: "2018-01-01 08:00",
toDate: "2018-01-01 10:00",
color: colorSet.getIndex(0).brighten(0)
},
];
var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "name";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.inversed = true;

First, what errors are you getting or what is the result and how it differs from your wanted result? After some testing I think that you're getting the "Invalid argument supplied for foreach()" error. In that case try:

foreach ($data2 as $datarow) {
     echo $datarow;
}

Let me know if this was the fix you were looking for!