0

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;
Thomas Lyle
  • 33
  • 1
  • 7

1 Answers1

0

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

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

Steve
  • 1,853
  • 16
  • 30
  • Questions that are about undefined variables should not be answered. They should be closed as a duplicate of [PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset”](//stackoverflow.com/q/4261133/) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Aug 11 '18 at 17:49
  • OK, cheers, noted for the future. – Steve Aug 11 '18 at 17:56