Mysql query
In theory relvar attributes are unordered and therefore you shouldn't be doing this. However, in MySQL, I believe you can query the directory to get the names as well as the "order" of the table columns. You can get the column names and order like so:
select column_name, ordinal_position from information_schema.columns where table_name='my_table';
However, I doubt this will help you too much. What you are doing smells like bad database design, and if you can't do anything with the design, which unfortunately happens sometimes, you can get rows from your table in a programming language for example. PHP and then use loops to "manually" count the nonblank cells in whatever cells you like. You can get strings in an array and then access individual cells by specifying the array index.
If you are happy to do this, then why not? It definitely shouldn't be too hard.
a source to share