Php Mysql Query Number Of Rows In A Matrix