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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题