Hey y'all,
In short : a page with results from an archery-match. Each archer is displayed with his score, #misses, #10's and #9's.
Goal : to change a lot of the scores, and to have the concerned records updated when SUBMIT is pressed.
This is what I've got so far :
<?php require_once('../Connections/URSTAB.php'); ?>
<?php
$editFormActionModify = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormActionModify .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "update_results")) {
for ($i = 0; $i < count($PID); $i++) {
if (($RSCORE[$i]) > 0) {
$values .="('$MYEAR[$i]','$MCODE[$i]',$PID[$i],$RSCORE[$i],$RMISS[$i],$R10S[$i],$R9S[$i]),";
}
}
$values = substr($values,0,-1);
$insertSQL = sprintf("UPDATE results SET (MYEAR, MCODE, PID, RSCORE, RMISS, R10S, R9S) VALUES $values");
mysql_select_db($database_URSTAB, $URSTAB);
$Result1 = mysql_query($insertSQL, $URSTAB) or die(mysql_error());
$updateGoTo = "modifyresults_next.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
Now only including one of the records here (page is 1708 lines long, so...)
<?php if (isset($row_RESULTS_R_DEB['PNAME'])) {?>
<tr>
<td colspan="5"><b><?php print $lang['048'] ?></b></td>
</tr>
<tr>
<td bgcolor="#999999" width="200"><?php print $lang['041'] ?></td>
<td width="60" align="center" bgcolor="#999999"><?php print $lang['042'] ?></td>
<td width="30" align="center" bgcolor="#999999"><?php print $lang['043'] ?></td>
<td width="30" align="center" bgcolor="#999999"><?php print $lang['044'] ?></td>
<td width="30" align="center" bgcolor="#999999"><?php print $lang['045'] ?></td>
</tr>
<?php do {
mysql_select_db($database_URSTAB, $URSTAB);
$query_RESULTS_R_DEB_SCORE = "SELECT * FROM results WHERE MCODE = '" . $_GET['MCODE'] . "' AND PID = " . $row_RESULTS_R_DEB['PID'];
$RESULTS_R_DEB_SCORE = mysql_query($query_RESULTS_R_DEB_SCORE, $URSTAB) or die(mysql_error());
$row_RESULTS_R_DEB_SCORE = mysql_fetch_assoc($RESULTS_R_DEB_SCORE);
$totalRows_RESULTS_R_DEB_SCORE = mysql_num_rows($RESULTS_R_DEB_SCORE);
?>
<tr>
<td><?php echo $row_RESULTS_R_DEB['PNAME']; ?></td>
<td align="center"><input name="RSCORE[]" type="text" size="3" maxlength="3" value="<?php if(isset($row_RESULTS_R_DEB_SCORE['RSCORE'])) { echo $row_RESULTS_R_DEB_SCORE['RSCORE']; } else { print '0'; } ?>" /></td>
<td align="center"><input name="RMISS[]" type="text" size="2" maxlength="2" value="<?php if(isset($row_RESULTS_R_DEB_SCORE['RMISS'])) { echo $row_RESULTS_R_DEB_SCORE['RMISS']; } else { print '0'; } ?>" /></td>
<td align="center"><input name="R10S[]" type="text" size="2" maxlength="2" value="<?php if(isset($row_RESULTS_R_DEB_SCORE['R10S'])) { echo $row_RESULTS_R_DEB_SCORE['R10S']; } else { print '0'; } ?>" /></td>
<td align="center"><input name="R9S[]" type="text" size="2" maxlength="2" value="<?php if(isset($row_RESULTS_R_DEB_SCORE['R9S'])) { echo $row_RESULTS_R_DEB_SCORE['R9S']; } else { print '0'; } ?>" /><input name="PID[]" type="hidden" value="<?php echo $row_RESULTS_R_DEB['PID']; ?>" /><input name="MCODE[]" type="hidden" value="<?php echo $_GET['MCODE']; ?>" /><input name="MYEAR[]" type="hidden" value="<?php echo $_GET['MYEAR']; ?>" /></td>
</tr>
<?php
mysql_free_result($RESULTS_R_DEB_SCORE);
} while ($row_RESULTS_R_DEB = mysql_fetch_assoc($RESULTS_R_DEB)); ?>
<tr>
<td colspan="5"> </td>
</tr>
<?php } ?>
I know I've left out some of the DB selectors and other stuff, but I guess you get the general idea of how the data is passed (=> names of the form fields).
This solution doens't work off course, since the SQL statement is incorrect. I only started out like this because I'm using the same stuff to initially CREATE the records (INSERT INTO statement instead of UPDATE SET), and that works fine.
Problem is I've got no idea how to perform an UPDATE in this way...
Thanks for the help already!
Pink