evenmonkeys Posted August 18, 2013 Share Posted August 18, 2013 (edited) Just to play around with what I'm learning.. I made a battleship game. I'm sure there are better ways to do what I did.. but this is what I have and I'd like to figure out a faster, cleaner way to make this work. I have a table where each row is a square on the battleship board. If a ship has three squares to it, there are three rows for the ship, each corresponding to a column (x) and a row (y). What I am trying to do.. is that when a player creates a board, how can I validate that when they click the "validate my board" button, it checks to see if any of the rows entered for that game have matching x and y entries. For example, if Ship 1 has 1x1, 2x1, and 3x1.. and Ship 2 has 2x1, 2x2 and 2x3, then it's clear that the ships overlap at 2x1. Well, there are 20 rows (squares) that need to be validated all at once. How can I do this without having 14 pages of <if> statements? Any help would be appreciated. (This may be better in the PHP forums.. but I wasn't sure since it requires the database as well. Move if necessary.) Edited August 18, 2013 by evenmonkeys Quote Link to comment https://forums.phpfreaks.com/topic/281328-how-to-validate-2-columns-do-not-match-over-20-rows/ Share on other sites More sharing options...
Barand Posted August 19, 2013 Share Posted August 19, 2013 how are you storing the data? Quote Link to comment https://forums.phpfreaks.com/topic/281328-how-to-validate-2-columns-do-not-match-over-20-rows/#findComment-1445885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.