Skip to content

Instantly share code, notes, and snippets.

@harini-ua
Created May 15, 2017 13:37
Show Gist options
  • Save harini-ua/d2453358fb3d185e066227fff6c5b34e to your computer and use it in GitHub Desktop.
Save harini-ua/d2453358fb3d185e066227fff6c5b34e to your computer and use it in GitHub Desktop.
<?php
include_once 'conf.php';
$row = '';
$link = getConnection();
$page = 1;
$pageinlist = 2;
$status = "ASC";
$colon = "username";
if (isset($_GET['page'])) {
$page = $_GET['page'] - 1;
}
$startpage = ($page - 1) * $pageinlist;
if (isset($_GET['status'])) {
$status = $_GET['status'];
}
if (isset($_GET['colon'])) {
$colon = $_GET['colon'];
}
$query = "SELECT SQL_CALC_FOUND_ROWS `username`,`email`,`created_at`,`text` FROM userstext";
if($colon) {
$query .= " ORDER BY ".$colon;
if ($status) {
$query .= " ".$status;
}
}
$query .= " LIMIT ".$startpage.", ".$pageinlist;
$rezult = mysqli_query($link, $query);
echo "<div style='position: relative;left: 10%; ;text-align: center;'>";
echo "<table border='1' style='border: solid; width: 75%'>";
echo "<thead>";
echo "<tr>";
echo "<td>"."<a href='adminpanel.php?page=$i&status=asc&colon=username'>asc</a>";
echo " / ";
echo "<a href='adminpanel.php?page=$i&status=desc&colon=username'>desc</a>"."</td>";
echo "<td>"."<a href='adminpanel.php?page=$i&status=asc&colon=email'>asc</a>";
echo " / ";
echo "<a href='adminpanel.php?page=$i&status=desc&colon=email'>desc</a>"."</td>";
echo "<td>"."<a href='adminpanel.php?page=$i&status=asc&colon=created_at'>asc</a>";
echo " / ";
echo "<a href='adminpanel.php?page=$i&status=desc&colon=created_at'>desc</a>"."</td>";
echo "<td>"."<a href='adminpanel.php?page=$i&status=asc&colon=text'>asc</a>";
echo " / ";
echo "<a href='adminpanel.php?page=$i&status=desc&colon=text'>desc</a>"."</td>";
echo "</tr>";
echo "<tr>";
echo "<th>".'username'."</th>";
echo "<th>".'email'."</th>";
echo "<th>".'created_at'."</th>";
echo "<th>".'text'."</th>";
echo "</tr>";
echo "</thead>";
while($row = mysqli_fetch_array($rezult))
{
$username = $row['username'];
$email = $row['email'];
$created_at = $row['created_at'];
$text = $row['text'];
echo "<tbody >";
echo "<tr>";
echo "<td>" . $username . "</td>";
echo "<td>" . $email . "</td>";
echo "<td>" . $created_at. "</td>";
echo "<td>" . $text. "</td>";
echo "</tr>";
echo "</tbody>";
}
echo "</table>";
echo "</div>";
$result = mysql_query("SELECT FOUND_ROWS()", $link);
$num_pages = mysql_result($result, 0);
for($i = 1; $i <= $num_pages; $i++) {
echo "<a href=" .'adminpanel.php'."?page=".$i."&status=".$status."&colon=".$colon.">".$i."</a> ";
}
if(!$rezult){if(!$rezult) die('ERROR'.mysqli_error($link));}
mysqli_close($link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment