Explore an easy way to fix MySQL Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. You can either disable it permanently or turn it off before executing an update/delete statements and turn it back on after. SET SQL_SAFE_UPDATES=0; will fix it for you, but be careful, you are not protected against DELETE FROM table statement anymore.
If you need to only loop through the diagonal elements of the two-dimensional array you can use the following C# code (but should be more or less the same for any programming language). It calculates the diagonal index based on a simple formula and has O(n) complexity, where n = max(width, height)