Zakladny princip by mohol byt teda nasledovny:
tim1 - id timu1 z formulara
tim2 - id timu2 z formulara
gtim1 - goly timu1 z formulara
gtim2 - goly timu2 z formulara
Kód:
<?php
$required = array('tim1', 'tim2', 'gtim1', 'gtim2');
$err = FALSE;
foreach($required as $value) {
if(isset($_POST[$value]) && ctype_digit($_POST[$value])) {
$$value = $_POST[$value];
} else {
$err = TRUE;
break;
}
}
if(!$err) {
$tim1Query = "UPDATE tabuka_a SET gplus = gplus + ".$gtim1.", gminus = gminus + ".$gtim2." WHERE id = ".$tim1." LIMIT 1";
$tim2Query = "UPDATE tabuka_a SET gplus = gplus + ".$gtim2.", gminus = gminus + ".$gtim1." WHERE id = ".$tim2." LIMIT 1";
$tim1Res = mysql_query($tim1Query);
$tim2Res = mysql_query($tim2Query);
$query = "SELECT id, gplus, gminus FROM tabuka_a WHERE id IN(".$tim1.", ".$tim2.")";
$res = mysql_query($query);
while(list($id, $gplus, $gminus) = mysql_fetch_row($res)) {
echo 'Tim s id '.$id.' ma '.$gplus.' plusovych golov a '.$gminus.' minusovych golov.<br>';
}
}
?>