dseax40600 2018-08-11 17:30
浏览 92
已采纳

未定义的变量:$ table [duplicate]

I am getting a Undefined variable: $table -- everything is returning correctly in my table - if i declare the variable first $table = '' it only returns the last result?

output data to tables
            for ($i=1; $i < count($port_number) ; $i++) {
                $port_des_ = substr($port_number[$i], strpos($port_number[$i], "STRING:") + 8);
                $port_des_1 = substr($port_des1[$i], strpos($port_des1[$i], "STRING:") + 8);    
                $speeds_1 = substr($speeds_[$i], strpos($speeds_[$i], "Gauge32:") + 8);
                if(strpos( $speeds_1 , '1000000000' ) !== false){$speeds_1 = "1Gb";}
                if(strpos( $speeds_1 , '10000000' ) !== false){$speeds_1 = "10Mb";}
                if(strpos( $speeds_1 , '100000000' ) !== false){$speeds_1 = "100Mb";}  
                if (preg_match('/40Gig/',$port_des_) & strpos( $speeds_1 , '4294967295' ))$speeds_1 = "40Gb";  
                if(strpos( $speeds_1 , '4294967295' ) !== false){$speeds_1 = "10Gb";}                                       
                $updown_stat_1 = substr($updown_stat[$i], strpos($updown_stat[$i], " ") + 8);   
                    if(strpos( $updown_stat_1 , 'up(1)' ) !== false){$updown_stat_1 = "UP";}
                    else{$updown_stat_1 = "DOWN";}
                $inbytes = substr($in_byte[$i], strpos($in_byte[$i], "Counter32") + 10);
                $outbytes = substr($out_byte[$i], strpos($out_byte[$i], "Counter32") + 10);
                $inerrors = substr($in_error[$i], strpos($in_error[$i], "Counter32") + 10);
                $outerrors = substr($out_error[$i], strpos($out_error[$i], "Counter32") + 10);
                $inucasts = substr($in_cast[$i], strpos($in_cast[$i], "Counter32") + 10);
                $outucasts = substr($out_cast[$i], strpos($out_cast[$i], "Counter32") + 10);
                $inbcasts = substr($in_ncast[$i], strpos($in_ncast[$i], "Counter32") + 10);
                $outbcasts = substr($out_ncast[$i], strpos($out_ncast[$i], "Counter32") + 10);
                $poe_watts = substr($poe_wat[$i], strpos($poe_wat[$i], "SNMPv2") +53);

                // table rows / data
                $table .= '<tr>                  
                <td>'.$port_des_.'</td>
                <td>'.$updown_stat_1.'</td>
                <td>'.$speeds_1.'</td>
                <td>'.$poe_watts.'</td>
                <td>'.$port_des_1.'</td>
                <td>'.$inbytes.'</td>
                <td>'.$outbytes.'</td>
                <td>'.$inerrors.'</td>
                <td>'.$outerrors.'</td>
                <td>'.$inucasts.'</td>
                <td>'.$outucasts.'</td>
                <td>'.$inbcasts.'</td>
                <td>'.$outbcasts.'</td>
                </tr>';
            }               

            echo $table;
</div>
  • 写回答

1条回答 默认 最新

  • dongyigua4468 2018-08-11 17:39
    关注

    It sounds like you are declaring $table inside your for loop.

    Add $table = ''; above your for loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)