doujiang1913 2012-05-17 09:17
浏览 91

PHP:未定义的偏移量错误

The below-provided code is used to fill an array "data".

$query1="SELECT * FROM tab1, tab2 WHERE tab1.column1=tab2.column2;";
    $result1=DatabaseConnector::ExecuteQueryArray($query1);
    $data = array();
    $i = 0;
    foreach ($result1 as $row):
        $data[] = array(
            array($i,array("xxx",' EE112',$row['column3'],'FT445'),"2004-03-01 10:00","2004-03-01 14:00"));
        $i++;
    endforeach;

When I try reading data from the array, the error "Undefined offset: 1" occurs. The funny thing is that when I filled "data" array using $data = and not $data[] =, there was no error, just the last row was filled. The error is produced by line $bar = new GanttBar(..). I tried to substitute $row['column3'] by some string "xxx", but there was the same error.

for($i=0; $i<count($data); ++$i) {
        $bar = new GanttBar($data[$i][0],$data[$i][1],$data[$i][2],$data[$i][3]);
        $graph->Add($bar);
    }
  • 写回答

2条回答 默认 最新

  • doucan8246326 2012-05-17 09:22
    关注

    Isn't

    $data[] = array("xxx",' EE112',$row['column3'],'FT445',"2004-03-01 10:00","2004-03-01 14:00");
    

    just enough, data structure should be as simple as possible.

    Ok, if you want that structure.

    $data[] = array(array("xxx",' EE112',$row['column3'],'FT445'),"2004-03-01 10:00","2004-03-01 14:00");
    

    Then

    foreach($data as $i => $var) {
        $bar = new GanttBar($i, $var[0], $var[1], $var[2]);
        $graph->Add($bar);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘