0

I have an old existing internal web app in PHP/mysql that I have been debugging after we were forced to eliminate register_globals. I'm no PHP programmer, but I seem to have most of the errors fixed and the site seems 99% functional. I'm stumped on this one though. The code works, and I believe the line in question pads the end of the table. I get a null (blank) undefined index error with every page load on this line:

 $results[$label] || $results[$label] = " ";

A more complete look here:

  $cols = 4;
  $order = array();

  $rows = ceil( count($labels) / $cols);

  $labels = array_pad($labels, $cols*$rows, '');

  $newlabels = array_chunk($labels, $rows);  

  for ($i = 0; $i < count($newlabels[0]); $i++) {
     for ($j = 0; $j < count($newlabels); $j++) {
       array_push($order, $newlabels[$j][$i]);
     }
  }

  echo "<p>";
  echo "<table width=100% border=1 noshade>";

  $form = "general-add-form.php";

  $anchor = " <a href=\"$form?tablename=$tablename&col1=$col1&ID=$ID\">
              $results[$col1]</a>";

  echo "<tr>
            <th>$col1</th><td>$anchor</td>
            <th>$col2</th><td>$results[$col2]</td>
        </tr>";

  echo "<tr>";

  foreach ($order as $label) {
     $results[$label] || $results[$label] = "&nbsp;";
     echo "<th>", ucfirst($label), "</th>";
     echo "<td>$results[$label]</td>";
     $z++; if ( ! ($z % $cols) ) echo "</tr><tr>";
  }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mark M
  • 29
  • 5
  • I found plenty of references to those errors. What got me was the undefined being null. --Thanks – Mark M May 15 '17 at 01:02

1 Answers1

1

If you are using PHP 7, change that line to:

$results[$label] = $results[$label] ?? "&nbsp;";

If you are using anything less than PHP 7, do:

$results[$label] = (isset($results[$label])) ? $results[$label] : "&nbsp;";
Enstage
  • 2,106
  • 13
  • 20
  • Thank's for the straight answer with no snark. PHP is not my day job, and sometimes you just want to fix it and move on. I figured it was just about that, but I couldn't get the syntax right. --FistBump – Mark M May 15 '17 at 00:30