-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjoueurs.php
161 lines (138 loc) · 4.12 KB
/
joueurs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
session_start();
function search()
{
global $bdd;
if(isset($_GET['page']) && is_numeric($_GET['page']))//valeur par défaut de la variable $page = 1
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
//valeur LIMIT = nombre de lignes (joueurs() affichés par page
$pagination = 2;
//valeur OFFSET = à partir de quelle ligne
$limit_start = ($page - 1) * $pagination;
//requête avec variables $pagination et $limit_start
$cond = array();
$query = "SELECT position, prenom, nom, image, Pseudo
FROM positions
INNER JOIN joueurs
ON joueur = id";
//déterminer le nombre de joueurs dans la base de données
$requete_2 = "SELECT COUNT(*) AS nb_total FROM joueurs";
$resultat_2 = mysqli_query($bdd, $requete_2);
$donnees = mysqli_fetch_array($resultat_2);
$nb_total = $donnees['nb_total'];
$nb_pages = ceil($nb_total / $pagination);//calcul du nombre de pages nécessaire à l'affichage de tous les joueurs (compte tenu de $pagination)
if(isset($_POST['posMin']))
{
$posMin = $_POST['posMin'];
$cond[] = "position >= '$posMin'";
}
if(isset($_POST['posMax']))
{
$posMax = $_POST['posMax'];
$cond[] = "position <= '$posMax'";
}
if(isset($_POST['day']))
{
$day = $_POST['day'];
$cond[] = "journee = '$day'";
}
if(isset($_POST['saison']))
{
$saison = $_POST['saison'];
$cond[] = "saison = '$saison'";
}
if (count($cond))
// Bien penser à mettre les espaces
$query .= ' WHERE '.implode(' AND ', $cond).' ORDER BY position ASC LIMIT 10';
else
$query .= ' ORDER BY position ASC LIMIT '.$pagination.' OFFSET '. $limit_start;
$result = mysqli_query($bdd, $query);
echo "<table class='table table-condensed table-striped'>";
echo "<tr><th>Position</th><th>Prénom</th><th>Nom</th><th>image</th><th>Vedette</th><th>Supprimer</th></tr>";
while($data = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$data['position']."</td>";
echo "<td>".$data['prenom']."</td>";
echo "<td>".$data['nom']."</td>";
echo "<td>"."<img src='".strip_tags($data['image'])."'/>"."</td>";
echo "<td>"; ?>
<form action="joueurs.php" method="POST">
<input type="hidden" name="pseudo" value="<?php echo $data['Pseudo']; ?>" >
<input type="submit" value="Choisir">
</form>
<?php
echo "</td>";
echo "<td>"; ?>
<form action="joueurs.php" method="POST">
<input type="hidden" name="supPseudo" value="<?php echo $data['Pseudo']; ?>" >
<input type="submit" value="Supprimer">
</form>
<?php
echo "</td>";
echo "</tr>";
}
for($i = 1; $i <= $nb_pages; $i++)//boucle pour afficher un lien pour chaque page (utilisation de variable $nb_pages)
{
if ($i == $page)
echo " $i";
else
echo "<a href='joueurs.php?page=" . $i . "' >" . $i . "</a> ";//affichage du lien : prévoir l'envoi de la variable GET
}
mysqli_free_result($result);
mysqli_free_result($resultat_2);
}
?>
<?php include("header.php"); ?>
<br><br><br><br>
<?php
if($bdd == True)
search();
else // Mais si elle rate…
echo "Erreur, de connexion à la base de données"; // On affiche un message d'erreur
?>
<div class="container" style="top:10px">
<form name="search" method="POST" action="joueurs.php" role="form">
<label>Rechercher les joueurs</label>
<button id="btn" type="submit" class="btn btn-default">OK</button><br/>
Position Min :
<input type="text" name="posMin">
Position Max :
<input type="text" name="posMax">
Journée :
<select type="text" name="day" class="input-small">
<?php
$day = mysqli_query($bdd,
'SELECT journee
FROM positions
GROUP BY journee'
);
while($data = mysqli_fetch_assoc($day))
{
echo "<option>".$data['journee']."</option>";
}
?>
</select>
Saison :
<select type="text" name="saison" class="input-small">
<?php
$saison = mysqli_query($bdd,
'SELECT saison
FROM positions
GROUP BY saison'
);
while($data = mysqli_fetch_assoc($saison))
{
echo "<option>".$data['saison']."</option>";
}
?>
</select>
</form>
</div>
<?php include("footer.php"); ?>