douxun7992 2019-06-24 11:49
浏览 75

如何使用(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;
  • 写回答

1条回答 默认 最新

  • douzhang1955 2019-06-24 12:16
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站