add page functionality for groups
This commit is contained in:
@@ -80,6 +80,55 @@ function search20GroupsFromNByStatus($db, $n, $keyword, $status) {
|
||||
return $q;
|
||||
}
|
||||
|
||||
function searchSomeGroupsByStatus($db, $n, $m, $keyword, $status) {
|
||||
$q = $db->prepare("
|
||||
SELECT
|
||||
`groupID`,
|
||||
`name`,
|
||||
`status`,
|
||||
`description`
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`name` LIKE :keyword AND
|
||||
FIND_IN_SET (`status`, :statuses)
|
||||
ORDER BY
|
||||
`name`
|
||||
LIMIT
|
||||
:n, :m
|
||||
");
|
||||
|
||||
$keyword = "%$keyword%";
|
||||
$q->bindParam(':keyword', $keyword);
|
||||
$q->bindParam(':n', $n, PDO::PARAM_INT);
|
||||
$q->bindParam(':m', $m, PDO::PARAM_INT);
|
||||
$statuses = implode(',', $status);
|
||||
$q->bindParam(':statuses', $statuses);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function countSomeGroupsByStatus($db, $keyword, $status) {
|
||||
$q = $db->prepare("
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`name` LIKE :keyword AND
|
||||
FIND_IN_SET (`status`, :statuses)
|
||||
ORDER BY
|
||||
`name`
|
||||
");
|
||||
|
||||
$keyword = "%$keyword%";
|
||||
$q->bindParam(':keyword', $keyword);
|
||||
$statuses = implode(',', $status);
|
||||
$q->bindParam(':statuses', $statuses);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function changeGroupStatusByID($db, $id, $status) {
|
||||
$q = $db->query("
|
||||
UPDATE
|
||||
|
||||
@@ -62,8 +62,6 @@
|
||||
<!-- function test_input taken from http://www.w3schools.com/php/php_form_validation.asp -->
|
||||
<?php
|
||||
$search = "";
|
||||
$listn = 0; // TODO: add page functionality
|
||||
$listm = 20;
|
||||
$currentpage = 1;
|
||||
$perpage = 20;
|
||||
$status = $groupstatus = array();
|
||||
@@ -109,6 +107,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
|
||||
}
|
||||
|
||||
$listn = ($currentpage-1) * $perpage;
|
||||
$listm = $currentpage * $perpage;
|
||||
|
||||
function test_input($data) {
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
@@ -224,7 +225,12 @@ function test_input($data) {
|
||||
|
||||
<div class="admin-userpage">
|
||||
<p class="pagenumber">Showing results
|
||||
<?php $pages = countSomeUsersByStatus($db, $search, $status);
|
||||
<?php
|
||||
if ($pagetype == "user") {
|
||||
$pages = countSomeUsersByStatus($db, $search, $status);
|
||||
} else {
|
||||
$pages = countSomeGroupsByStatus($db, $search, $status);
|
||||
}
|
||||
$countresults = $pages->fetchColumn();
|
||||
$mincount = min($listm, $countresults);
|
||||
echo "$listn to $mincount out of $countresults"; ?></p><br>
|
||||
@@ -237,7 +243,7 @@ function test_input($data) {
|
||||
onchange="this.form.submit()"
|
||||
value="">
|
||||
<?php
|
||||
for ($i=1; $i <= $countresults / $perpage + 1; $i++) {
|
||||
for ($i=1; $i <= ceil($countresults / $perpage); $i++) {
|
||||
if ($currentpage == $i) {
|
||||
echo "<option value='$i' selected>$i</option>";
|
||||
} else {
|
||||
@@ -263,8 +269,8 @@ function test_input($data) {
|
||||
|
||||
<!-- Table construction via php PDO. -->
|
||||
<?php
|
||||
$listn = ($currentpage-1) * 20;
|
||||
$listm = $currentpage * 20;
|
||||
$listn = ($currentpage-1) * $perpage;
|
||||
$listm = $currentpage * $perpage;
|
||||
|
||||
if ($pagetype == 'user') {
|
||||
$q = searchSomeUsersByStatus($db, $listn, $listm, $search, $status);
|
||||
@@ -305,7 +311,7 @@ function test_input($data) {
|
||||
");
|
||||
}
|
||||
} else {
|
||||
$q = search20GroupsFromNByStatus($db, $listn, $search, $groupstatus);
|
||||
$q = searchSomeGroupsByStatus($db, $listn, $listm, $search, $groupstatus);
|
||||
|
||||
while ($group = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||
$groupID = $group['groupID'];
|
||||
|
||||
Reference in New Issue
Block a user