...and $number_of_columns is undefined here.

Maybe you should enable error reporting in your development environment to catch such things earlier, see https://wiki.phpmyadmin.net/pma/Developer_guidelines#Best_practices