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.

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

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名