Sei sulla pagina 1di 22

PHP project

Sport office

Simon Amboise Vianney Kieken 1

Demand

List all students with their sports

List all games of the year

Give possibility to complete database : add a new student, enter game’s results…

Return some statistics about games : win, defeat, average, number of remaining game …

Database design

3 tables :

Student

ID Student Name Surname Phone Year Email

Sport

ID Sport

Sport

ID Student Name Surname Phone Year Email Sport ID Sport Sport Game ID game Date Place

Game

ID game Date Place Opposing team Win/Lose Result

ID Student Name Surname Phone Year Email Sport ID Sport Sport Game ID game Date Place

Web page render

Web page render 4

Code main page

<html>

<head>

<title>Sports office</title> <style type="text/css">

<!--

body { background-image: url(background_neige2.jpg);

}

.Style1 { font-family: "Comic Sans MS"; font-size: 24px; color: #000000; font-weight: bold;

}

.Style2 {font-family: "Comic Sans MS"; font-size: 24px; color: #0099FF; font-weight: bold; } .Style3 { font-family: "Comic Sans MS";

color: #000000; font-size: 16px;

}

-->

</style>

</head>

Code main page

<body> <div align="center" class="Style1">Sports Office</div> <p><span class="Style2">Select your choice:</span></p>

<p><br /> <span class="Style3"><a href="sport.php">See the sports proposed by the sport office</a></p> <p><br /> <a href="result.php">See the matches and their results</a></p> <p><br /> <a href="students.php">See all the registered students and register a new student</a></p> <p><br /> <a href="onesportcalendarandteam.php">Choose one sport and see the team and the calendar</a></p> <p><br /> <a href="querriesname.php">Choose one student and see his performances</a></span></p> </body> </html>

Web page render

Sport.php

7
7

Code sport.php

<?php include 'connect2server.php'; include 'opendb.php';

$query="SELECT sport FROM sport ORDER BY sport"; $result=mysql_query($query) or die('query SELECT failed');

while($row=mysql_fetch_array($result,MYSQL_ASSOC))

{

echo "{$row['sport']}<br>";

}

?>

<p><br /> <span class="Style2"><a href="main2.html">Return to the main page</a></span></p>

Web page render

Result.php

Web page render Result.php 9

Code result.php

$query = 'SELECT matches.date,matches.place,matches.opposing_side,matches.result,sport.sport FROM matches,sport WHERE date<=CURRENT_DATE AND matches.ID_sport=sport.ID_sport ORDER BY date DESC'; $result = mysql_query($query) or die ('query SELECT failed'); $total = mysql_num_rows($result);

Code result.php

if($total) { // Start of the table echo '<table bgcolor="rgb(11, 57, 77)">'."\n"; // First rows (presentation) echo '<tr>'; echo '<td bgcolor="rgb(100, 193, 234)"><b><u>Date</u></b></td>'; echo '<td bgcolor="rgb(100, 193, 234)"><b><u>Place</u></b></td>'; echo '<td bgcolor="rgb(100, 193, 234)"><b><u>Opposing side</u></b></td>'; echo '<td bgcolor="rgb(100, 193, 234)"><b><u>Result</u></b></td>'; echo '<td bgcolor="rgb(100, 193, 234)"><b><u>Sport</u></b></td>'; echo '</tr>'."\n"; // read the mysql table while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td bgcolor="rgb(255, 255, 255)">'.$row["date"].'</td>'; echo '<td bgcolor="rgb(255, 255, 255)">'.$row["place"].'</td>'; echo '<td bgcolor="rgb(255, 255, 255)">'.$row["opposing_side"].'</td>'; echo '<td bgcolor="rgb(255, 255, 255)">'.$row["result"].'</td>'; echo '<td bgcolor="rgb(255, 255, 255)">'.$row["sport"].'</td>'; echo '</tr>'."\n";

}

echo '</table>'."\n";

// end of table.

}

else echo 'No entry in this table

‘;

Web page render

Add Result.php

Web page render Add Result.php 12

Code add result.php

if (isset($_POST['add']))

{

include 'connect2server.php'; include 'opendb.php';

$Ndate=$_POST['Ndate'];

$Nplace=$_POST['Nplace'];

$Nopposing_side=$_POST['Nopposing_side'];

$Nresult=$_POST['Nresult'];

$Nwin=$_POST['Nwin'];

$Nsport=$_POST['Nsport'];

$query = "INSERT INTO matches (date, place, opposing_side, win_lose, result,ID_sport) VALUES('$Ndate' , '$Nplace' , '$Nopposing_side','$Nwin','$Nresult', '$Nsport')"; mysql_query($query) or die('Error, insert query failed'); mysql_close();

echo "The match between the school and $Nopposing_side played at : $Nplace the $Ndate as the result : $Nresult is now registered";

}

13

Code add result.php

else

?>

{

<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">

Date (YYYY-MM-JJ) :

Place : <input type="text"

Opposing side : <input type="text"

<input type="text"

name ="Ndate" id ="Ndate"> <br>

name ="Nplace" id ="Nplace"> <br>

name ="Nopposing_side" id ="Nopposing_side" > <br>

Result : <input type="text"

Is the school the winner ? <input type="radio" name="Nwin" value="W" checked="checked" /> Yes <input type="radio" name="Nwin" value="L" /> No <br> <?php include 'connect2server.php';

include 'opendb.php'; $query2 = mysql_query("SELECT ID_sport,sport FROM sport ORDER BY sport;") or die (mysql_error()); echo "sport : "; echo '<select name="Nsport">'; while ($row = mysql_fetch_array($query2,MYSQL_ASSOC))

name ="Nresult" id ="Nresult"> <br>

{

echo '<option value="' . $row['ID_sport'] . '">' . $row['sport'] . '</option>';

}

echo '</select>'; mysql_close(); ?> <br><br>

Click here when you have completed all the informations : <input type="submit" value = "Add this result" name="add" id="add"> <br>

14

</form>

Web page render

Student.php

Web page render Student.php 15

Code student.php

$query = 'SELECT student.name,student.last_name,student.year,student.phone_number,student.email,sp ort.sport FROM student,sport WHERE student.ID_sport=sport.ID_sport ORDER BY name'; $result = mysql_query($query) or die ('query SELECT failed');

Web page render

Add Student.php

Web page render Add Student.php 17

Web page render

One sport informations.php

Web page render One sport informations.php 18
Web page render One sport informations.php 18

18

Code onesportinfo.php

if (isset($_POST['add']))

{

……

 

$Nsport=$_POST['Nsport']; $query = "SELECT DISTINCT name,last_name FROM student WHERE student.ID_sport='$Nsport' ORDER BY name"; $result = mysql_query($query) or die('Error, insert query failed');

$query2 = "SELECT DISTINCT date,place,opposing_side,result FROM matches WHERE matches.ID_sport='$Nsport' ORDER BY date DESC"; $result2 = mysql_query($query2) or die('Error, insert query failed');

//creation of the two tables

}

Web page render

Queries name.php

Web page render Queries name.php 20
Web page render Queries name.php 20

Code queries name.php

if (isset($_POST['Sstudent']))

{

……… $Nstudent=$_POST['Nstudent']; $query = "SELECT COUNT(ID_match) FROM matches,student WHERE student.ID_student='$Nstudent' AND student.ID_sport=matches.ID_sport";

$query2 = "SELECT COUNT(ID_match) FROM matches,student WHERE student.ID_student='$Nstudent' AND student.ID_sport=matches.ID_sport AND matches.win_lose='W' ";

$query3 = "SELECT COUNT(ID_match) FROM matches,student WHERE student.ID_student='$Nstudent' AND student.ID_sport=matches.ID_sport AND matches.win_lose='L' ";

}

if (isset($_POST['Sglobal']))

{

$query = "SELECT COUNT(ID_match) FROM matches WHERE win_lose='W' ";

$query2 = "SELECT COUNT(*) FROM matches ";

}

else

{

//display post

}

Conclusion

Still

database but already very useful for the sport office organization

improvements

in

this

some

Conclusion Still database but already very useful for the sport office organization improvements in this some