Skip to content
This repository was archived by the owner on May 18, 2021. It is now read-only.

Commit 3850d96

Browse files
author
cammygames
committed
Fixed Pageination
1 parent 5d1d007 commit 3850d96

7 files changed

Lines changed: 284 additions & 481 deletions

File tree

views/gangs.php

Lines changed: 43 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -60,84 +60,54 @@
6060
<tbody>
6161
<?php
6262
if (!$db_connection->connect_errno) {
63+
if (isset($_GET["page"])) {
64+
$page = $_GET["page"];
65+
}else {
66+
$page=1;
67+
}
6368

64-
if (!(isset($_POST['Gpagenum']))) {
65-
$pagenum = 1;
66-
} else {
67-
$pagenum = $_POST['Gpagenum'];
68-
}
69+
$start_from = ($page-1) * $page_rows;
70+
$max = 'LIMIT ' . $start_from . ',' . $page_rows;
71+
72+
if (isset($_POST['searchText'])) {
73+
$searchText = $_POST['searchText'];
6974

70-
$sql = "SELECT * FROM `gangs`;";
75+
if (isset($_POST['pid'])) {
76+
$sql = "SELECT * FROM `gangs` WHERE `owner` LIKE '%" . $searchText . "%' " . $max . " ;";
77+
} else {
78+
$sql = "SELECT * FROM `gangs` WHERE `name` LIKE '%" . $searchText . "%' " . $max . " ;";
79+
}
80+
} else {
81+
$sql = "SELECT * FROM `gangs` " . $max . " ;";
82+
}
83+
$result_of_query = $db_connection->query($sql);
84+
while ($row = mysqli_fetch_assoc($result_of_query)) {
85+
echo "<tr>";
86+
echo "<td>" . $row["id"] . "</td>";
87+
echo "<td>" . $row["name"] . "</td>";
88+
echo "<td>" . $row["owner"] . "</td>";
89+
echo "<td>" . $row["bank"] . "</td>";
90+
echo "<td>" . $row["maxmembers"] . "</td>";
91+
echo "<td>" . $row["active"] . "</td>";
92+
echo "<td><form method='post' action='editGang.php' name='PlayerEdit'>";
93+
echo "<input id='gID' type='hidden' name='gID' value='" . $row["id"] . "'>";
94+
echo "<input class='btn btn-sm btn-primary' type='submit' name='edit' value='" . $lang['edit'] . "'>";
95+
echo "</form></td>";
96+
echo "</tr>";
97+
};
98+
echo "</tbody></table>";
7199

72-
$result_of_query = $db_connection->query($sql);
73-
$rows = mysqli_num_rows($result_of_query);
100+
$sql = "SELECT * FROM `gangs`";
101+
$result_of_query = $db_connection->query($sql);
102+
$total_records = mysqli_num_rows($result_of_query);
103+
$total_pages = ceil($total_records / $page_rows);
104+
echo "<center><a href='gangs.php?page=1'>".'First Page'."</a> ";
74105

75-
$last = ceil($rows / $page_rows);
106+
for ($i=1; $i<=$total_pages; $i++) {
107+
echo "<a href='gangs.php?page=".$i."'>|".$i."|</a> ";
108+
};
76109

77-
if ($pagenum < 1) {
78-
$pagenum = 1;
79-
} elseif ($pagenum > $last) {
80-
$pagenum = $last;
81-
}
82-
83-
$max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
84-
85-
if (isset($_POST['searchText'])) {
86-
$searchText = $_POST['searchText'];
87-
88-
if (isset($_POST['pid'])) {
89-
$sql = "SELECT * FROM `gangs` WHERE `owner` LIKE '%" . $searchText . "%' " . $max . " ;";
90-
} else {
91-
$sql = "SELECT * FROM `gangs` WHERE `name` LIKE '%" . $searchText . "%' " . $max . " ;";
92-
}
93-
} else {
94-
$sql = "SELECT * FROM `gangs` " . $max . " ;";
95-
}
96-
$result_of_query = $db_connection->query($sql);
97-
while ($row = mysqli_fetch_assoc($result_of_query)) {
98-
echo "<tr>";
99-
echo "<td>" . $row["id"] . "</td>";
100-
echo "<td>" . $row["name"] . "</td>";
101-
echo "<td>" . $row["owner"] . "</td>";
102-
echo "<td>" . $row["bank"] . "</td>";
103-
echo "<td>" . $row["maxmembers"] . "</td>";
104-
echo "<td>" . $row["active"] . "</td>";
105-
echo "<td><form method='post' action='editGang.php' name='PlayerEdit'>";
106-
echo "<input id='gID' type='hidden' name='gID' value='" . $row["id"] . "'>";
107-
echo "<input class='btn btn-sm btn-primary' type='submit' name='edit' value='" . $lang['edit'] . "'>";
108-
echo "</form></td>";
109-
echo "</tr>";
110-
};
111-
echo "</tbody></table>";
112-
echo "<table><thead>";
113-
echo "<br>";
114-
if ($pagenum == 1) {
115-
} else {
116-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
117-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='1'>";
118-
echo "<input type='submit' value=' <<-" . $lang['first'] . " '>";
119-
echo "</form></th>";
120-
$previous = $pagenum - 1;
121-
echo "<th><form style='float:right;' method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
122-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $previous . "'>";
123-
echo "<input type='submit' value=' <-" . $lang['previous'] . " '>";
124-
echo "</form></th>";
125-
}
126-
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
127-
if ($pagenum == $last) {
128-
} else {
129-
$next = $pagenum + 1;
130-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
131-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $next . "'>";
132-
echo "<input type='submit' value=' " . $lang['next'] . " -> '>";
133-
echo "</form></th>";
134-
echo " ";
135-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
136-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $last . "'>";
137-
echo "<input type='submit' value=' " . $lang['last'] . " ->> '>";
138-
echo "</form></th>";
139-
}
140-
echo "</thead></table>";
110+
echo "<a href='gangs.php?page=$total_pages'>".'Last Page'."</a></center>";
141111
} else {
142112
$this->errors[] = "Database connection problem.";
143113
}

views/houses.php

Lines changed: 42 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -57,80 +57,53 @@
5757
<?php
5858
if (!$db_connection->connect_errno) {
5959

60-
if (!(isset($_POST['pagenum']))) {
61-
$pagenum = 1;
62-
} else {
63-
$pagenum = $_POST['pagenum'];
64-
}
60+
if (isset($_GET["page"])) {
61+
$page = $_GET["page"];
62+
}else {
63+
$page=1;
64+
}
6565

66-
$sql = "SELECT * FROM `houses`;";
66+
$start_from = ($page-1) * $page_rows;
67+
$max = 'LIMIT ' . $start_from . ',' . $page_rows;
68+
69+
if (isset($_POST['searchText'])) {
70+
$searchText = $_POST['searchText'];
6771

68-
$result_of_query = $db_connection->query($sql);
69-
$rows = mysqli_num_rows($result_of_query);
70-
$last = ceil($rows / $page_rows);
72+
if (isset($_POST['pos'])) {
73+
$sql = "SELECT * FROM `houses` WHERE `pos` LIKE '%" . $searchText . "%' " . $max . " ;";
74+
} else {
75+
$sql = "SELECT * FROM `houses` WHERE `pid` LIKE '%" . $searchText . "%' " . $max . " ;";
76+
}
77+
} else {
78+
$sql = "SELECT * FROM `houses` " . $max . " ;";
79+
}
80+
$result_of_query = $db_connection->query($sql);
81+
while ($row = mysqli_fetch_assoc($result_of_query)) {
82+
$hID = $row["id"];
83+
echo "<tr>";
84+
echo "<td>" . $row["pid"] . "</td>";
85+
echo "<td>" . $row["pos"] . "</td>";
86+
echo "<td>" . $row["owned"] . "</td>";
87+
echo "<td><form method='post' action='editHouse.php' name='PlayerEdit'>";
88+
echo "<input id='hID' type='hidden' name='hID' value='" . $hID . "'>";
89+
echo "<input class='btn btn-sm btn-primary' type='submit' name='edit' value='" . $lang['edit'] . "'>";
90+
echo "</form></td>";
91+
echo "</tr>";
92+
};
93+
echo "</tbody></table>";
7194

72-
if ($pagenum < 1) {
73-
$pagenum = 1;
74-
} elseif ($pagenum > $last) {
75-
$pagenum = $last;
76-
}
95+
$sql = "SELECT * FROM `houses`";
96+
$result_of_query = $db_connection->query($sql);
97+
$total_records = mysqli_num_rows($result_of_query);
98+
$total_pages = ceil($total_records / $page_rows);
99+
echo "<center><a href='houses.php?page=1'>".'First Page'."</a> ";
77100

78-
$max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
101+
for ($i=1; $i<=$total_pages; $i++) {
102+
echo "<a href='houses.php?page=".$i."'>|".$i."|</a> ";
103+
};
79104

80-
if (isset($_POST['searchText'])) {
81-
$searchText = $_POST['searchText'];
82-
83-
if (isset($_POST['pos'])) {
84-
$sql = "SELECT * FROM `houses` WHERE `pos` LIKE '%" . $searchText . "%' " . $max . " ;";
85-
} else {
86-
$sql = "SELECT * FROM `houses` WHERE `pid` LIKE '%" . $searchText . "%' " . $max . " ;";
87-
}
88-
} else {
89-
$sql = "SELECT * FROM `houses` " . $max . " ;";
90-
}
91-
$result_of_query = $db_connection->query($sql);
92-
while ($row = mysqli_fetch_assoc($result_of_query)) {
93-
$hID = $row["id"];
94-
echo "<tr>";
95-
echo "<td>" . $row["pid"] . "</td>";
96-
echo "<td>" . $row["pos"] . "</td>";
97-
echo "<td>" . $row["owned"] . "</td>";
98-
echo "<td><form method='post' action='editHouse.php' name='PlayerEdit'>";
99-
echo "<input id='hID' type='hidden' name='hID' value='" . $hID . "'>";
100-
echo "<input class='btn btn-sm btn-primary' type='submit' name='edit' value='" . $lang['edit'] . "'>";
101-
echo "</form></td>";
102-
echo "</tr>";
103-
};
104-
echo "</tbody></table>";
105-
echo "<table><thead>";
106-
echo "<br>";
107-
if ($pagenum == 1) {
108-
} else {
109-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
110-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='1'>";
111-
echo "<input type='submit' value=' <<-" . $lang['first'] . " '>";
112-
echo "</form></th>";
113-
$previous = $pagenum - 1;
114-
echo "<th><form style='float:right;' method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
115-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $previous . "'>";
116-
echo "<input type='submit' value=' <-" . $lang['previous'] . " '>";
117-
echo "</form></th>";
118-
}
119-
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
120-
if ($pagenum == $last) {
121-
} else {
122-
$next = $pagenum + 1;
123-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
124-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $next . "'>";
125-
echo "<input type='submit' value=' " . $lang['next'] . " -> '>";
126-
echo "</form></th>";
127-
echo " ";
128-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
129-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $last . "'>";
130-
echo "<input type='submit' value=' " . $lang['last'] . " ->> '>";
131-
echo "</form></th>";
132-
}
133-
echo "</thead></table>";
105+
echo "<a href='houses.php?page=$total_pages'>".'Last Page'."</a></center>";
106+
134107
} else {
135108
$this->errors[] = "Database connection problem.";
136109
}

views/medics.php

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -43,70 +43,43 @@
4343
<tbody>
4444
<?php
4545
if (!$db_connection->connect_errno) {
46-
if (!(isset($_POST['pagenum']))) {
47-
$pagenum = 1;
48-
} else {
49-
$pagenum = $_POST['pagenum'];
50-
}
46+
if (isset($_GET["page"])) {
47+
$page = $_GET["page"];
48+
}else {
49+
$page=1;
50+
}
5151

52-
$sql = "SELECT * FROM `players`;";
52+
$start_from = ($page-1) * $page_rows;
53+
$max = 'LIMIT ' . $start_from . ',' . $page_rows;
54+
55+
$sql = "SELECT `name`,`mediclevel`,`playerid` FROM `players` WHERE `mediclevel` >= '1' ORDER BY `mediclevel` " . $max . " ;";
56+
$result_of_query = $db_connection->query($sql);
57+
while ($row = mysqli_fetch_assoc($result_of_query)) {
58+
$playersID = $row["playerid"];
59+
echo "<tr>";
60+
echo "<td>" . $row["name"] . "</td>";
61+
echo "<td>" . $playersID . "</td>";
62+
echo "<td>" . $row["mediclevel"] . "</td>";
63+
echo "<td><form method='post' action='editPlayer.php' name='PlayerEdit'>";
64+
echo "<input id='playerId' type='hidden' name='playerId' value='" . $playersID . "'>";
65+
echo "<input class='btn btn-sm btn-primary' type='submit' name='edit' value='" . $lang['edit'] . "'>";
66+
echo "</form></td>";
67+
echo "</tr>";
68+
};
69+
echo "</tbody></table>";
5370

54-
$result_of_query = $db_connection->query($sql);
55-
$rows = mysqli_num_rows($result_of_query);
56-
$last = ceil($rows / $page_rows);
71+
$sql = "SELECT * FROM `players` WHERE `mediclevel` >= '1'";
72+
$result_of_query = $db_connection->query($sql);
73+
$total_records = mysqli_num_rows($result_of_query);
74+
$total_pages = ceil($total_records / $page_rows);
75+
echo "<center><a href='medics.php?page=1'>".'First Page'."</a> ";
5776

58-
if ($pagenum < 1) {
59-
$pagenum = 1;
60-
} elseif ($pagenum > $last) {
61-
$pagenum = $last;
62-
}
77+
for ($i=1; $i<=$total_pages; $i++) {
78+
echo "<a href='medics.php?page=".$i."'>|".$i."|</a> ";
79+
};
6380

64-
$max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
65-
66-
$sql = "SELECT `name`,`mediclevel`,`playerid` FROM `players` WHERE `mediclevel` >= '1' ORDER BY `mediclevel` " . $max . " ;";
67-
$result_of_query = $db_connection->query($sql);
68-
while ($row = mysqli_fetch_assoc($result_of_query)) {
69-
$playersID = $row["playerid"];
70-
echo "<tr>";
71-
echo "<td>" . $row["name"] . "</td>";
72-
echo "<td>" . $playersID . "</td>";
73-
echo "<td>" . $row["mediclevel"] . "</td>";
74-
echo "<td><form method='post' action='editPlayer.php' name='PlayerEdit'>";
75-
echo "<input id='playerId' type='hidden' name='playerId' value='" . $playersID . "'>";
76-
echo "<input class='btn btn-sm btn-primary' type='submit' name='edit' value='" . $lang['edit'] . "'>";
77-
echo "</form></td>";
78-
echo "</tr>";
79-
};
80-
echo "</tbody></table>";
81-
echo "<table><thead>";
82-
echo "<br>";
83-
if ($pagenum == 1) {
84-
} else {
85-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
86-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='1'>";
87-
echo "<input type='submit' value=' <<-" . $lang['first'] . " '>";
88-
echo "</form></th>";
89-
$previous = $pagenum - 1;
90-
echo "<th><form style='float:right;' method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
91-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $previous . "'>";
92-
echo "<input type='submit' value=' <-" . $lang['previous'] . " '>";
93-
echo "</form></th>";
94-
}
95-
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
96-
if ($pagenum == $last) {
97-
} else {
98-
$next = $pagenum + 1;
99-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
100-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $next . "'>";
101-
echo "<input type='submit' value=' " . $lang['next'] . " -> '>";
102-
echo "</form></th>";
103-
echo " ";
104-
echo "<th><form method='post' action='" . $_SERVER['PHP_SELF'] . "' name='Gpagenum'>";
105-
echo "<input id='Gpagenum' type='hidden' name='Gpagenum' value='" . $last . "'>";
106-
echo "<input type='submit' value=' " . $lang['last'] . " ->> '>";
107-
echo "</form></th>";
108-
}
109-
echo "</thead></table>";
81+
echo "<a href='medics.php?page=$total_pages'>".'Last Page'."</a></center>";
82+
11083
} else {
11184
$this->errors[] = "Database connection problem.";
11285
}

0 commit comments

Comments
 (0)