|
60 | 60 | <tbody> |
61 | 61 | <?php |
62 | 62 | if (!$db_connection->connect_errno) { |
| 63 | + if (isset($_GET["page"])) { |
| 64 | + $page = $_GET["page"]; |
| 65 | + }else { |
| 66 | + $page=1; |
| 67 | + } |
63 | 68 |
|
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']; |
69 | 74 |
|
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>"; |
71 | 99 |
|
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> "; |
74 | 105 |
|
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 | + }; |
76 | 109 |
|
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>"; |
141 | 111 | } else { |
142 | 112 | $this->errors[] = "Database connection problem."; |
143 | 113 | } |
|
0 commit comments