im trying to make a game of battleships and im currently stuck trying to get a way to be able to take a shot.
so far there is a table on the database and it will contain all 0's i will then query the table and fill a table on the page if there is a 0 it will put a blank image. then when you click the button for the location of the shot you wish to take i want it to update the table value to a 1 to indicate that that grid location has been used so then when i repopulate the table it will put a different image.
im using ajax to refresh the page every few seconds this is the code from the div that gets refreshed. the code works fine right now but im stuck on what to do next ive tried giving each button a unique id but that means ill need to have 100 functions for the sql. whats the best way to go about this problem so i can take a shot and it will change a value in the table thats stored on the database
PHP Code:
$conn=mysql_connect($host,$username,$password);
@mysql_select_db($db_name)
or die
("<b>Unable to select database - named: ".$db_name);
$query="SELECT * FROM Grid";
$result=mysql_query($query);
$num = 10;
$i=0;
echo "<table border=5>";
while ($i <$num)
{
echo "<tr>";
for( $col = 1; $col <=10; $col+=1)
{
$query = mysql_result($result, $i, $col);
if($query > 0)
{
if($query ==1)
{
echo '<td><button onclick="SubmitShot();"><img src ="miss.JPG"/></button></td>';
}
else
echo '<td><button onclick="SubmitShot();"><img src ="hit.JPG"/></button></td>';
}
else
echo '<td><button onclick="SubmitShot();"><img src ="white.JPG"/></button></td>';
$counter++;
}
echo "</tr>";
$i++;
}
echo "</table>";
?>