$row3 = mysql_fetch_array($res3);
}
else
{
$res3 = mysql_query("SELECT Doma, ZabMjach, PropMjach FROM MatchRezult,Matches, Chempionats
WHERE Gost='$vgost' and
Matches.idMatch=MatchRezult.idMatch and
NameChemp='Чемпионат России' and
Chempionats.idChemp=Matches.idChemp".$wyear."ORDER BY Doma ");
for($mas=1;$mas<$zapis;$mas++)
$row3 = mysql_fetch_array($res3);
}
$c++;
}
while($c<$i && $row3 = mysql_fetch_array($res3));
}//else
}
while($c<$i);
$c=1;
$zapis=1;
do {
if($k==$c)
{
printf("
<td width='25' bgcolor='#939393'>
</td>");
$c++;
}
else
{
$doma = $myrow["ID"];
$res2 = mysql_query("SELECT Gost, ZabMjach, PropMjach FROM MatchRezult,Matches, Chempionats
WHERE Doma='$doma' and
Matches.idMatch=MatchRezult.idMatch and
NameChemp='Чемпионат России' and
Chempionats.idChemp=Matches.idChemp".$wyear."ORDER BY Gost ");
$row2 = mysql_fetch_array($res2);
$gost = $row2['Gost'];
if($gost == '')
{
printf("
<td width='25'>
<table width='35' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='tablerrez2'> </td>
</tr>
<tr>
<td class='tablerrez3'> %s</td>
</tr>
</table>
</td>",$gostarray[$k][$c]);
$c++;
}
else
{
do {
$gost = $row2['Gost'];
if ($comarray[$c]==$gost)
{
printf("
<td width='25'>
<table width='35' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='tablerrez2'> %s:%s</td>
</tr>
<tr>
<td class='tablerrez3'> %s</td>
</tr>
</table>
</td>",$row2['ZabMjach'],$row2['PropMjach'],$gostarray[$k][$c]);
$zapis++;
}
else
if($k==$c)
{
printf("
<td width='25' bgcolor='#939393'>
</td>");
$res2 = mysql_query("SELECT Gost, ZabMjach, PropMjach FROM MatchRezult,Matches, Chempionats
WHERE Doma='$doma' and
Matches.idMatch=MatchRezult.idMatch and
NameChemp='Чемпионат России' and
Chempionats.idChemp=Matches.idChemp".$wyear."ORDER BY Gost ");
for($mas=1;$mas<$c;$mas++)
$row2 = mysql_fetch_array($res2);
}
else
{
printf("
<td width='25'>
<table width='35' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='tablerrez2'> </td>
</tr>
<tr>
<td class='tablerrez3'> %s</td>
</tr>
</table>
</td>",$gostarray[$k][$c]);
$res2 = mysql_query("SELECT Gost, ZabMjach, PropMjach FROM MatchRezult,Matches, Chempionats
WHERE Doma='$doma' and
Matches.idMatch=MatchRezult.idMatch and
NameChemp='Чемпионат России' and
Chempionats.idChemp=Matches.idChemp".$wyear."ORDER BY Gost ");
for($mas=1;$mas<$zapis;$mas++)
$row2 =
mysql_fetch_array($res2);
}
$c++;
}
while($c<$i && $row2 = mysql_fetch_array($res2));
}
}//else
}
while($c<$i);
$k++;
printf(" </tr>");
}
?>
</table>
<br>
<table width='222' height='24' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td width='41' class='main_border'><img src='img/doma.gif' width='41' height='21' /></td>
<td width='70' class='pod'> -дома </td>
<td width='41' class='main_border'><img src='img/vgost.gif' width='39' height='21' /></td>
<td width='70' class='pod'>-в гостях </td>
</tr>
</table>
</table></td>
</tr>
<!--Нижний блок-->
<?php include("blocks/footer.php");?>
</table>
</body>
</html>
New_match.php
<?php
include("blocks/bd.php");/* Соединяемся с БД */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Добавление</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="main_border">
<!--Шапка сайта-->
<? include("blocks/header.php");?>
<tr>
<td><table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<!--Левый блок-->
<?php include("blocks/left.php");?>
<td width="737" valign="top" class="spisok">
<form name="form1" method="post" action="add_match.php">
<p>
<label>Выберите чемпионат </label>
<?php
printf(" <select class='pod' name='idChemp' >");
$result = mysql_query("SELECT idChemp, NameChemp, Year FROM Chempionats", $db);
$myrow = mysql_fetch_array($result);
do {
printf("<option value='%s'>%s %s",$myrow['idChemp'],$myrow['NameChemp'],$myrow['Year']);
}
while($myrow = mysql_fetch_array($result));
printf("</select>");
?>
</p>
<p>
<label>Выберите команду, которая играла дома </label>
<?php
printf(" <select class='pod' size=1 type=text name='Doma' >");
$result = mysql_query("SELECT idCom, NameCom FROM Command", $db);
$myrow = mysql_fetch_array($result);
do {
printf("<option value='%s'>%s",$myrow['idCom'],$myrow['NameCom']);
}
while($myrow = mysql_fetch_array($result));
printf("</select>");
?>
</p>
<p>
<label>Выберите команду, которая играла в гостях </label>
<?php
printf(" <select class='pod' size=1 type=text name='Gost' >");
$result = mysql_query("SELECT idCom, NameCom FROM Command", $db);
$myrow = mysql_fetch_array($result);
do {
printf("<option value='%s'>%s",$myrow['idCom'],$myrow['NameCom']);
}
while($myrow = mysql_fetch_array($result));
printf("</select>");
?>
</p>
<p>
<label>Введитедату матча
<input name="datematch" type="text" />
</label>
</p>
<p>
<label>Введите количество мячей, забитых первой командой
<input name="zabmjach" type="text" />
</label>
</p>
<p>
<label>Введите количество мячей, забитых второй командой
<input name="propmjach" type="text" />
</label>
</p>
<p>
<label>Введите город, где проводился матч
<input name="gorod" type="text" id="date" />
</label>
</p>
<p>
<label>Выберите судей матча <br />
<?php
$result = mysql_query("SELECT * FROM Sudja", $db);
$myrow = mysql_fetch_array($result);
do {
printf("<input type='checkbox' name='Check[]' value='%s' /> %s %s %s
</label><br>",$myrow['idSud'],$myrow['FSud'],$myrow['Isud'],$myrow['OSud']);
}
while($myrow = mysql_fetch_array($result));
?>
</p>
<p>
<label>
<input type="submit" name="Submit" id="submit" value="Занести данные в базу" />
</label>
</p>
</form>
</td>
</tr>
</table></td>
</tr>
<!--Нижний блок-->
<?php include("blocks/footer.php");?>
</table>
</body>
</html>
add_match.php
<?php
include("blocks/bd.php");
if(isset($_POST['idChemp'])) {$idChemp = $_POST['idChemp']; if($idChemp == '') {unset($idChemp);}}
if(isset($_POST['Doma'])) {$Doma = $_POST['Doma']; if($Doma == '') {unset($Doma);}}
if(isset($_POST['Gost'])) {$Gost = $_POST['Gost']; if($Gost == '') {unset($Gost);}}
if(isset($_POST['datematch'])) {$DateMatch = $_POST['datematch']; if($DateMatch == '') {unset($DateMatch);}}
if(isset($_POST['zabmjach'])) {$ZabMjach= $_POST['zabmjach'];if($ZabMjach == '') {unset($ZabMjach);}}
if(isset($_POST['propmjach'])) {$PropMjach = $_POST['propmjach']; if($PropMjach == '') {unset($PropMjach);}}
if(isset($_POST['gorod'])) {$CityMatch = $_POST['gorod']; if($CityMatch == '') {unset($CityMatch);}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Добавление данных в базу</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="main_border">
<!--Шапка сайта-->
<? include("blocks/header.php");?>
<tr>
<td><table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<!--Левый блок-->
<?php include("blocks/left.php");?>
<td width="737" valign="top" class="view">
<?php
if(isset($idChemp) && isset($Doma) && isset($Gost) && isset($DateMatch) && isset($ZabMjach) && isset($PropMjach) && isset($CityMatch) &&isset($_POST['Check']))
{
if($Doma == $Gost)
echo "<p>Команда не может играть сама с собой. Выберите другую комамнду.</p>";
else
{
$prov = mysql_query("SELECT Matches.idMatch
FROM Matches, MatchRezult
WHERE Matches.idMatch=MatchRezult.idMatch and idChemp='$idChemp' and Doma='$Doma' and Gost = '$Gost'");
$row=mysql_fetch_array($prov);
if(isset($row[0]))
echo "В рамках данного чемпионат этот матч уже состоялся. Возможно вы ошиблись при вводе данных.";
else
{
$result = mysql_query("INSERT INTO Matches (idChemp, DateMatch, CityMatch)
VALUES('$idChemp','$DateMatch','$CityMatch')");
if($result == 'true')
{
$sel = mysql_query("SELECT idMatch FROM Matches ORDER BY idMatch desc limit 1");
$row = mysql_fetch_array($sel);
$idMatch=$row['idMatch'];
$result2 = mysql_query("INSERT INTO MatchRezult (idMatch, Doma, Gost, ZabMjach, PropMjach)
VALUES('$idMatch','$Doma','$Gost', '$ZabMjach','$PropMjach')");
if($result2 == 'true')
{
$my_check = $_POST['Check'];
$len = sizeof($my_check);
for($i=0; $i<$len; $i++)
{
$result3 = mysql_query("INSERT INTO SudjiInMatch (idMatch, idSud)
VALUES('$idMatch','$my_check[$i]')");
}
if ($result3 == 'true')
{
$sel = mysql_query("SELECT idCom FROM CommandInChemp WHERE idCom='Doma'");
$row = mysql_fetch_array($sel);
if(!isset($row[0]))
{
$result4 =
mysql_query("INSERT INTO CommandInChemp (idChemp, idCom)
VALUES('$idChemp','$Doma')");
}
if ($result4 == 'true')
{
$sel = mysql_query("SELECT idCom FROM CommandInChemp WHERE idCom='Gost'");
$row = mysql_fetch_array($sel);
if(!isset($row[0]))
{
$result5 = mysql_query("INSERT INTO CommandInChemp (idChemp, idCom)
VALUES('$idChemp','$Gost')");
}
if($result5 != 'true')
echo "<p>Ошибка. Данные в базу не занесены!</p>";
}
echo "<p>Данные успешно занесены в базу!</p>";
}
}
}
else
echo "<p>Ошибка. Данные в базу не занесены!</p>";
}
}
}
else
{
echo "<p>Вы ввели не всю информацию, поэтому данные не могут быть добавлены в базу.</p>";
}
?>
</td>
</tr>
</table></td>
</tr>
<!--Нижний блок-->
<?php include("blocks/footer.php");?>
</table>
</body>
</html>