Hello all.. Very new to php and am working on an online strategy game as a precursor to my business websites. I am having a problem coming up with something I thought would be simple.
My intention was to have a list of units display on the screen using checkboxes to select which units to attack. In order for me to have a select all button I had to use a bit of javascript in there. My problem is this... I thought I could just use 2 arrays and match them up so I would be able to run through the mysql database and update each unit that was checked. The arrays however come back only with the checkboxes that were checked so my idea for simply matching box 1 to unit 1 won't work. I just want to update a field called 'checked' in a mysql database to yes or no so I can call a routine that will go through the records to use in the combat.
If anybody has a better way of doing this since the way I thought would work won't I would appreciate a point in the right direction. I was thrilled to have the select all button finally work.
if(!$_POST['yes'] && !$_POST['no']){
?>
<TABLE ALIGN="center">
<tr>
<td>
<form action="selectattackers.php" method="post">
<input type="checkbox" value="on" name="allbox"
onclick="checkAll();"/> Select All<br />
<script language="javascript">
function checkAll(){
for (var i=0;i<document.forms[0].elements.length;i++)
{
var e=document.forms[0].elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox'))
{
e.checked=document.forms[0].allbox.checked;
}
}
}
</script>
<br>
<input name="yes" type="submit" value="Yes">
<input name="no" type="submit" value="No">
<br>
<?
$result3 = $db->query("SELECT * FROM UnitsZones WHERE OwnerID=\"" . $Owner . "\"");
while($unitstoattack= $db->fetch($result3)){
if($unitstoattack[Checked]=="Y"){
echo "Unit Number: $unitstoattack[UnitNumber] Zone:$unitstoattack[ZoneID] Description:$unitstoattack[UnitDescription]";
echo"<INPUT TYPE=checkbox NAME=checkbox[] VALUE=1>
<br>";
$unitnumberarray = array($unitstoattack[UnitNumber]);
}
}
?>
</form>
</td>
</tr>
</table>
<?
}
elseif($_POST['yes']){
for($i = 0; $i < 12; ++$i)
{
/*This is where I had planned on simply updating the field to Y in
* the mysqul database the 12 above was to be the sizeof the array
*
*/
echo "HI";
echo "$unitnumberarray[$i] <BR> ";
if($checkbox[$i]== true){echo "YAY";}
}
}
include("../includes/inc-footer.php");
?>