sammenlign 2 tabeller og opdater en tredje
Hej ekpserter.Hold lige fast for den her er måske lidt indviklet, men prøver at skrive det simpelt og forståeligt.
Jeg har 3 tabeller der skal indgå i en formel
Tabel 1: "calendar_events" (i denne ligger pladserne)
med felterne: EventNr, place1, place2, place3, place4, place5, place6, place7, place8, place9, place10.
Tabel 2: "tilmeldte" (i denne ligger deltagerne)
med feltet: turneringsnr.
Tabel 3: "members" (i denne tabel skal feltet "point" opdateres, alt efter hvilken plads man tildeler medlemmet).
Jeg skal lave en formel der udregner hvor mange point deltageren skal have.
Formelen skal se således ud: antal deltagere x 10 ÷ placering.
Her er hele min kode:
<?php require_once('../../Connections/connect.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE calendar_events SET place1=%s, place2=%s, place3=%s, place4=%s, place5=%s, place6=%s, place7=%s, place8=%s, place9=%s, place10=%s WHERE EventId=%s",
GetSQLValueString($_POST['place1'], "text"),
GetSQLValueString($_POST['place2'], "text"),
GetSQLValueString($_POST['place3'], "text"),
GetSQLValueString($_POST['place4'], "text"),
GetSQLValueString($_POST['place5'], "text"),
GetSQLValueString($_POST['place6'], "text"),
GetSQLValueString($_POST['place7'], "text"),
GetSQLValueString($_POST['place8'], "text"),
GetSQLValueString($_POST['place9'], "text"),
GetSQLValueString($_POST['place10'], "text"),
GetSQLValueString($_POST['EventId'], "int"));
mysql_select_db($database_connect, $connect);
$Result1 = mysql_query($updateSQL, $connect) or die(mysql_error());
$updateGoTo = "admin_turneringer.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_Recordset1 = "1";
if (isset($_GET['EventId'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['EventId'] : addslashes($_GET['EventId']);
}
mysql_select_db($database_connect, $connect);
$query_Recordset1 = sprintf("SELECT * FROM calendar_events WHERE EventId = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Place1:</td>
<td><input type="text" name="place1" value="<?php echo $row_Recordset1['place1']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place2:</td>
<td><input type="text" name="place2" value="<?php echo $row_Recordset1['place2']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place3:</td>
<td><input type="text" name="place3" value="<?php echo $row_Recordset1['place3']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place4:</td>
<td><input type="text" name="place4" value="<?php echo $row_Recordset1['place4']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place5:</td>
<td><input type="text" name="place5" value="<?php echo $row_Recordset1['place5']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place6:</td>
<td><input type="text" name="place6" value="<?php echo $row_Recordset1['place6']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place7:</td>
<td><input type="text" name="place7" value="<?php echo $row_Recordset1['place7']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place8:</td>
<td><input type="text" name="place8" value="<?php echo $row_Recordset1['place8']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place9:</td>
<td><input type="text" name="place9" value="<?php echo $row_Recordset1['place9']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Place10:</td>
<td><input type="text" name="place10" value="<?php echo $row_Recordset1['place10']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Update record"></td>
</tr>
</table>
<input type="hidden" name="EventId" value="<?php echo $row_Recordset1['EventId']; ?>">
<input type="hidden" name="MM_update" value="form1">
</form>
<?php
mysql_free_result($Recordset1);
?>
-----------------------------------------------------
Jeg kunne forestille mig at man skulle lave formen på denne side, og så en side som "checker" hvilket navn man har skrevet på de forskellige pladser, og derefter opdater feltet "point" i tabellen members.
Håber i forstår hvad jeg mener og kan hjælpe mig. Hvis pointene ikke er gode nok, er jeg villig til at give flere. :-)
-rampagezz
