Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/projekt/classes/
card.php
collection.php
filtersort.php
lineup.php
user.php
lineup.php
119 lines UTF-8 Windows (CRLF)
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
<?php
include("./incl/default.php");
class Lineup
{
private $db;
public function __construct($dbconn)
{
$this->db = $dbconn;
//Slippa skicka $dbconn varje gång du kallar en metod
}
public function addtolineup($userid, $owned_id, $position)
{
try {
$sql = "SELECT owned_id, position FROM startelva
WHERE userid = ?";
$stmt = $this->db->prepare($sql);
$data = array($userid);
$stmt->execute($data);
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($res['owned_id'] == $owned_id) {
$playerExists = true;
break;
}
if ($res['position'] == $position) {
$positionExists = true;
}
}
if ($playerExists) {
} elseif ($positionExists) {
$sql = "UPDATE startelva SET owned_id = ?
WHERE userid = ? AND position = ?";
$stmt = $this->db->prepare($sql);
$data = array($owned_id, $userid, $position);
$stmt->execute($data);
} else {
$sql = "INSERT INTO startelva (userid, owned_id, position)
VALUES (?, ?, ?)";
$stmt = $this->db->prepare($sql);
$data = array($userid, $owned_id, $position);
$stmt->execute($data);
}
} catch (PDOException $e) {
echo $sql . "<br />" . $e->getMessage();
}
}
public function ownedplayersbypos($playernumber, $userid, $position)
{
try {
$sql = "SELECT owned_cards.id AS playerid, players.name AS name, players.position AS position
FROM owned_cards
RIGHT JOIN players ON owned_cards.player_id = players.id
WHERE owned_cards.user_id = ?
AND position = ?";
$stmt = $this->db->prepare($sql);
$data = array($userid, $position);
$stmt->execute($data);
echo '<label for=player' . $playernumber . '> Spelare' . $playernumber . '</label> <br>';
echo '<select name=' . $playernumber . ' required>: <br>';
echo "<option value=''></option>";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=" . htmlentities($res['playerid']) . ">" . htmlentities($res['name']) . "</option>";
}
echo '</select><br>';
} catch (PDOException $e) {
echo $sql . "<br />" . $e->getMessage();
}
}
public function displaylineup($userid)
{
try {
$sql = "SELECT players.name AS name, players.position AS position,
players.rating as rating, startelva.position AS stposition
FROM startelva
RIGHT JOIN owned_cards ON startelva.owned_id = owned_cards.id
RIGHT JOIN players ON owned_cards.player_id = players.id
WHERE startelva.userid = ?
ORDER BY stposition";
$stmt = $this->db->prepare($sql);
$data = array($userid);
$stmt->execute($data);
$html = "";
$average = 0;
$nuvarandeposition = 1;
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$resPosition = htmlentities($res['stposition']);
while ($nuvarandeposition < $resPosition) {
$html .= "<div id='empty'>";
$html .= "<p>0</p>";
$html .= "<p>0</p>";
$html .= "<p>0</p>";
$html .= "</div>";
$nuvarandeposition++;
//fyller gap med 00
}
$html .= "<div id='" . htmlentities($res['position']) . "'>";
$html .= "<p>" . htmlentities($res['name']) . "</p>";
$html .= "<p>" . htmlentities($res['position']) . "</p>";
$html .= "<p>" . htmlentities($res['rating']) . "</p>";
$html .= "</div>";
$average += $res['rating'];
$nuvarandeposition++;
}
$average /= 7;
echo "<h1> Rating: " . round($average) . "</h1> <p>";
echo '<div id="displaylineup">';
echo $html;
echo '</div>';
} catch (PDOException $e) {
echo $sql . "<br />" . $e->getMessage();
}
}
}