I load data onto a page using Ajax.
Here is the div (saleContentData) into which it is loaded:
<div class="resultsPage salesList">
<h2>Sales</h2>
<div class="salesFilters">
<form action="" method="POST">
<label for="date1">Start Date</label>
<input id="startDate" type="date" name="date1" value="Start Date" placeholder="Start Date" value="" min="1997-01-01" max="2030-12-31" />
<label for="date2">End Date</label>
<input id="endDate" type="date" name="date2" value="End Date" placeholder="End Date" value="" min="01-01-2010" max="01-01-2030" />
<button id="filterSales">Filter Sales</button>
<button id="resetFilter">Reset</button>
</form>
</div>
<div class=" salesContent">
<div class="saleContentData">
<div id="loading">
<img id="loading-image" src="assets/img/loader.gif" alt="Loading..." />
</div>
</div>
</div>
</div>
Here is the the script to display the data.
if (isset($_POST['start_date']) && $_POST['end_date']) {
$startDate = $_POST['start_date'];
$endDate = $_POST['end_date'];
$page_size = $_POST['page_size'];
$page_num = $_POST['page_num'];
showFiltered($startDate, $endDate, $page_size, $page_num);
} else if (isset($_POST['page_size']) && $_POST['page_num']) {
$page_size = $_POST['page_size'];
$page_num = $_POST['page_num'];
showNormal($page_size, $page_num);
} else {
showNormal();
}
function showNormal($page_number = 1, $page_size = 100)
{
//THE DATA
$data = getData("https://api.someapi.com/v2/sales?page_size=" . $page_size . "&page_number=" . $page_number);
//SHOW THE DATA
showRecords($data);
}
function showRecords($data)
{
//STATISTICS ABOUT THE DATA
$total_sales = ($data['page_summary']['total']);
$current_page = $data['page_summary']['page_number'];
echo $total_sales . " sales<br/>";
$num_pages = (ceil($total_sales / 100) * 100) / 100;
echo "<ul>";
// TO DISPLAY THE NUMBER OF PAGES
for ($page = 0; $page < $num_pages; $page++) {
if ($page == $current_page - 1) {
echo "<li class='page$page active'>" . $page + 1 . "</li>";
} else {
echo "<li class='page$page'>" . $page + 1 . "</li>";
}
}
echo "</ul>";
// TABLE WITH ALL SALES RECORDS
$sales = $data['sales'];
$counter = 1;
echo "<table id='salesTable'>
<thead><tr class='headingRow'><th class='image'></th><th class='productHD'>Product</th><th>Status</th><th>Revenue</th><th>Quantity</th><th class='dcCol'>DC</th><th>Order ID</th><th>Customer Name</th><th>Date</th></tr></thead>";
foreach ($sales as $key => $row) {
$col1 = $row['selling_price'];
$col2 = $row['quantity'];
$revenue = ($col1 * $col2);
echo "<tr><td class='num centerCol'><img src='placeholder.png'/></td><td class='productTitle'>" . $row['product_title'] . "</td><td class='centerCol'>" . $row['sale_status'] . "</td><td class='centerCol'>" . "R" . $revenue . "</td><td class='centerCol'>" . $row['quantity'] . "</td><td class='centerCol'>" . $row['dc'] . "</td><td class='centerCol'>" . $row['offer_id'] . "</td><td>" . $row['customer'] . "</td><td>" . $row['order_date'] . "</td></tr>";
}
echo "</table>";
}
Here is the Javscript that loads the page into the div:
$(".goSale").click(function () {
$.ajax({
method: "GET",
url: "getsales.php",
success: function (data) {
$(".saleContentData").html(data);
},
error: function (request, status, error) {
$(".saleContentData").html(error);
},
complete: function () {},
});
});
if I run the file by itself the list with the page numbers is displayed correctly and I see 1 TO 7. If I load the file using Ajax I get a different result and the page numbers are displayed as seven 1s.
Why would this be please?
So after looking at the HTML I see the list is not being generated and the numbers are loaded in the tag and so there is not list items.
Why would that be?
Does Ajax remove something?
Loading the page by itself
Loading the page using Ajax
Solved it:
echo "<ul id='pagesList'>";
for ($page = 0; $page < $num_pages; $page++) {
echo "<li class='page$page'>";
echo $page + 1;
echo "</li>";
}
echo "</ul>
The problem might be that you did not send any data to getsales.php page.
Check something like this.
How to send multiple data fields via Ajax?
If script you showed for displaying data is getsales.php, then you need to send there some data as below via ajax.
if (isset($_POST['start_date']) && $_POST['end_date']) {
$startDate = $_POST['start_date'];
$endDate = $_POST['end_date'];
$page_size = $_POST['page_size'];
$page_num = $_POST['page_num'];
}
showFiltered($startDate, $endDate, $page_size, $page_num);
i have a code for my table pagination.
but now i have a problem. the pagination is showing EVERY page. but i got over 900 pages.
ALSO: i need to use PDO
i want the pagination to work like this:
Image
i dont know how to make this in my already excisting code:
$per_page_html = '';
$page = 1;
$start=0;
if(!empty($_POST["page"])) {
$page = $_POST["page"];
$start=($page-1) * ROW_PER_PAGE;
}
$limit=" limit " . $start . "," . ROW_PER_PAGE;
$pagination_statement = $oConn->prepare($sql);
$pagination_statement->execute();
$row_count = $pagination_statement->rowCount();
if(!empty($row_count)){
$per_page_html .= "<div style='text-align:center;margin:20px 0px;'>";
$page_count=ceil($row_count/ROW_PER_PAGE);
if($page_count>1) {
for($i=1;$i<=$page_count;$i++){
if($i==$page){
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page current" />';
} else {
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page" />';
}
}
}
$per_page_html .= "</div>";
}
$query = $sql.$limit;
$pdo_statement = $oConn->prepare($query);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();
I dont see your table and your query in your question so I will give 2 complete examples tested on my demo site, you need to change it to your own variables.
Solution 1.
Here is the example pagination for items belong to a category, for simple pagination :
$perpage = "3";
//This limit of the page to show on each page
$n_stmt = $pdo->prepare("SELECT * FROM categories");
$n_stmt->execute();
$total_posts = $n_stmt->rowCount();
$total_pages = ceil($total_posts/$perpage);
$page = !empty($_GET['page']) && $_GET['page'] ? (int) $_GET['page'] : 1;
if($page < 1) $page = 1;
if($page > $total_pages) $page = $total_pages;
$limit = ($page - 1) * $perpage;
$pag_limit = 10;
$stmt = $pdo->prepare("SELECT * FROM categories ORDER BY created DESC LIMIT :limit, :perpage");
$stmt->bindValue(":limit",$limit, PDO::PARAM_INT);
$stmt->bindValue(":perpage",$perpage, PDO::PARAM_INT);
$stmt->execute();
while($news = $stmt->fetch(PDO::FETCH_ASSOC)){
// Do what ever you want here
}
And pagination:
<div class="pagination">
<?php if($page >1){?>
First
Preview
<?php } for($i = $page - $pag_limit; $i < $page + $pag_limit + 1; $i++){
if($i > 0 and $i <= $total_pages){
if($i == $page){?>
<?php echo $i;?>
<?php }else{?>
<?php echo $i;?>
<?php
}
}
?>
<?php } ?>
<?php if($page != $total_pages){?>
next
Last
<?php } ?>
</div>
Solution 2.
Here is pagination for search result with your codes, as I said this code works on my demo site you need to change your own variables and its in pdo:
define("ROW_PER_PAGE",10);
//this goes on top of your page
require_once("db.php");
$search_keyword = '';
if(!empty($_POST['search']['keyword'])) {
$search_keyword = htmlspecialchars(strip_tags($_POST["search"]["keyword"]), ENT_QUOTES);
}
$sql = 'SELECT * FROM posts WHERE title LIKE :keyword OR descriptions LIKE :keyword OR subject LIKE :keyword ORDER BY id DESC ';
/* Pagination Code starts */
$per_page_html = '';
$page = 1;
$start=0;
if(!empty($_POST["page"])) {
$page = $_POST["page"];
$start=($page-1) * ROW_PER_PAGE;
}
$limit=" limit " . $start . "," . ROW_PER_PAGE;
$pagination_statement = $pdo->prepare($sql);
$pagination_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pagination_statement->execute();
$row_count = $pagination_statement->rowCount();
if(!empty($row_count)){
$per_page_html .= "<div class=\"pagination\">";
$page_count=ceil($row_count/ROW_PER_PAGE);
if($page_count>1) {
for($i=1;$i<=$page_count;$i++){
if($i==$page){
$per_page_html .= "<input type=\"submit\" name=\"page\" value=" . $i . " class=\"btn-page current\" />";
} else {
$per_page_html .= "<input type=\"submit\" name=\"page\" value=" . $i . " class=\"btn-page\"/>";
}
}
}
$per_page_html .= "</div>";
}
$query = $sql.$limit;
$pdo_statement = $pdo->prepare($query);
$pdo_statement->bindValue(":keyword", "%" . $search_keyword . "%", PDO::PARAM_STR);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();
Your html part with pagination at the bottom and your result in form same as you can see
<form name="frmSearch" action="search/" method="post">
<div class="searchf">
<input type="text" name="search[keyword]" class="field" value="<?php echo $search_keyword; ?>" id="keyword" maxlength="25">
<input type="submit" name="submit" class="searchf-btn" value="Ara">
</div>
<?php
if(!empty($result)) {
foreach($result as $row) {
?>
<div class="news_box">
<a href="<?php echo htmlspecialchars($row["news_url"]);?>/" title="<?php echo htmlspecialchars($row["title"]);?>">
<div class="title"><h2><?php echo htmlspecialchars($row["title"]);?></h2></div>
<div class="image">
<img src="images/posts/<?php echo htmlspecialchars($row["img"]);?>" alt="<?php echo htmlspecialchars($row["title"]);?>"/></div>
<div class="spot"><?php echo htmlspecialchars($row["subject"]);?></div>
</a>
</div>
<?php
}
}
?>
<div class="cl"> </div>
//Here is pagination
<?php echo $per_page_html; ?>
</form>
I am using seo urls in demo, you need to set htaccess for links, or change pagination links like so : your_page.php?page=$i.
Both tested on my demo site and working, I used some filtering functions you can remove them.
I'm making a quiz. I displayed Q/A from db and the correct answer. How to see the answer of the specific question on clicking the Check Answer button.
<?php
if (isset($_GET['pageno'])){
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 1;
$offset = ($pageno - 1) * $no_of_records_per_page;
$conn = mysqli_connect("localhost", "root", "", "quizdb");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
$total_pages_sql = "SELECT COUNT(*) FROM entry1";
$result = mysqli_query($conn, $total_pages_sql);
$total_rows = mysqli_fetch_array($result)[0];
$total_pages = ceil($total_rows / $no_of_records_per_page);
$sql = "SELECT * FROM entry1 LIMIT $offset, $no_of_records_per_page";
$res_data = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($res_data)) {
include('server1.php');
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'quizdb';
$con = mysqli_connect($host, $user, $pass, $db);
$qno = $row["qno"];
$question = $row["question"];
$optiona = $row["optiona"];
$optionb = $row["optionb"];
$optionc = $row["optionc"];
$optiond = $row["optiond"];
$ans = $row["ans"];
echo '<br>Q ' . $qno . '. ';
echo '' . $question . '<br>';
echo '<input type="radio" name="options" value="optiona"></button>' . $optiona . '<br>';
echo '<input type="radio" name="options" value="optionb"></button>' . $optionb . '<br>';
echo '<input type="radio" name="options" value="optionc"></button>' . $optionc . '<br>';
echo '<input type="radio" name="options" value="optiond"></button>' . $optiond . '<br>';
echo '<form action="practice.php" method="post">
<input type="submit" name="submitans" value="Check Answer"></form>';
if (isset($_POST['submitans'])) {
echo '' . $ans . '<br>';
}
}
mysqli_close($conn);
?>
<ul class="pagination">
<li>First</li>
<li class="<?php if ($pageno <= 1) {
echo 'disabled';
} ?>">
<a href="<?php if ($pageno <= 1) {
echo '#';
} else {
echo "?pageno=" . ($pageno - 1);
} ?>">Prev</a></li>
<li class="<?php if ($pageno >= $total_pages) {
echo 'disabled';
} ?>">
<a href="<?php if ($pageno >= $total_pages) {
echo '#';
}
else {
echo "?pageno=" . ($pageno + 1);
} ?>">Next</a>
</li>
<li>Last</li>
</ul>
</body>
</html>
Expected Result - When I click next and I see another question, I click on Check Answer, then I see the answer of that question.
Actual Result - When I click next and I see another question, I click on Check Answer, then I go back to the first page and its answer is shown
I'm working on a real basic chat that is mostly php powered. I'd like to use jQuery to check for new messages and update the #cbox div every few seconds. So far I have tried accomplishing that using the code below. For a frame of reference, this is my first time including jQuery into any of my scripts, so the problem is likely a very simple error that I am overlooking in my newbishness.
The problem I'm running into is the #cbox div displays blank, it doesn't seem to be calling to chat_post.php at all. I will post that code as well, in case the problem is with that and not with my jQuery. To fix, I tried also including <div id='cbox'> in chat_post.php, but that yielded no results. At this point, I'm pretty much grasping at straws.
<div id='sb_content'>
<center><div id='chat'>
<div id='ribbon' style='position: relative; margin-top:-50px; margin-left:-32px;'><center><span class='ribbon'>chat box</span></center></div>
<div style='margin-top: -20px;'><center><span style='text-shadow: 0 0 0.2em #000;' class='admin'>admin</span> || <span style='text-shadow: 0 0 0.2em #000;' class='mod'>mod</span></center></div>
<div id="cbox">
<script>
$(document).ready(function() {
setInterval(function(){getUpdates()}, 2000);
});
function getUpdates() {
$("#cbox").load("chat_post.php");
}
</script>
</div>
<form name="message" method='post' action="chat_post.php" id="cbox_input">
<input name="usermsg"id='usermsg' type="text" size="63" maxlength="255" />
</form>
</div></center>
</div>
chat_post.php
<div id='cbox' align='left'>
<?php
$username = $_SESSION['login'];
$ug = $_SESSION['user_group'];
// Display messages
$sql = <<<SQL
SELECT *
FROM `chat_entries`
ORDER BY `ts` DESC
LIMIT 0,50
SQL;
$result = $db->query($sql);
$count = $result->num_rows;
if ($count != 0){
while ($row = mysqli_fetch_array($result)) {
$c_name = $row['author'];
$c_text = $row['text'];
$c_ts = $row['ts'];
$c_id = $row['id'];
$sqlm = <<<SQL
SELECT *
FROM `users`
WHERE username = '$c_name'
SQL;
$resultm = $db->query($sqlm);
$countm = $resultm->num_rows;
if ($count != 0){
while ($rowm = mysqli_fetch_array($resultm)) {
$c_level = $rowm['user_group'];
}
}
if ($c_level == 'mod') {
echo "
<a href='/user/" . $c_name . "' class='mod'>" . $c_name . "</a>
";
}
if ($c_level == 'admin') {
echo "
<a href='/user/" . $c_name . "' class='admin'>" . $c_name . "</a>
";
}
if ($c_level == 'member') {
echo "
<a href='/user/" . $c_name . "' class='member'>" . $c_name . "</a>
";
}
if ($c_level == 'guest') {
echo "
<i>" . $c_name . "</i>
";
}
echo "
: " . $c_text . "<div id='cbox_div'>";
echo "<span style='float:left;'><i>" . $c_ts . "</i></span>";
echo "<span style='float:right;'>";
if ($ug == 'mod' || $ug == 'admin'){
echo " <a href='#'>Delete</a> || <a href='#'>Block</a> ||";
}
if ($_SESSION['login']) {
echo "Report</span></div>
";
}
}
}
?>
After removing the extra id on chat_post.php, my code worked just fine. Funny how something so simple can really mess things up. (: Thank you everyone for your help!
This is my order list sortOrder.php:
<?php
$queryMain ="SELECT newsvid.id, newsvid.addName, newsvid.vidTitle, newsvid.vidType, newsvid.size, newsvid.url, newsvid.vidSD, newsvid.published, videoinformation.vidLD, videoinformation.vidYear, videoinformation.vidCity, videoinformation.vidZanr, videoinformation.vidZanr2, videoinformation.vidZanr3, videoinformation.vidQuality, videoinformation.vidTranslated, videoinformation.vidTime FROM newsvid, videoinformation WHERE newsvid.id = videoinformation.id AND approved='1'";
// Video type
$vType = isset($_GET['vType']) ? $_GET['vType'] : 'ALL';
$goodTypeParam = array("AnyType", "Film", "Serials", "Cartoon", "Anime");
if (in_array($vType, $goodTypeParam)) {
if($vType == 'AnyType'){}
else{$queryMain .= " AND newsvid.vidType ='".$_GET['vType']."'";}
}
//Video Genre one
$vGenre = isset($_GET['vGenre']) ? $_GET['vGenre'] : 'ALL';
$goodGenreParam = array("AnyGenre1", "Action", "Adventure", "Comedy", "Crime", "Faction", "Fantasy", "Historical", "Horror", "Mystery", "Paranoid", "Philosophical", "Political", "Realistic", "Romance", "Saga", "Satire", "Science-Fiction", "Slice-Of-Life", "Speculative", "Anime");
if (in_array($vGenre, $goodGenreParam)) {
if($vGenre == 'AnyGenre1'){}
else{$queryMain .= " AND ( videoinformation.vidZanr ='".$_GET['vGenre']."' OR videoinformation.vidZanr2 ='".$_GET['vGenre']."' OR videoinformation.vidZanr3 ='".$_GET['vGenre']."')";}
}
//Video Genre two
$vGenre2 = isset($_GET['vGenre2']) ? $_GET['vGenre2'] : 'ALL';
$goodGenre2Param = array("AnyGenre2", "Action2", "Adventure2", "Comedy2", "Crime2", "Faction2", "Fantasy2", "Historical2", "Horror2", "Mystery2", "Paranoid2", "Philosophical2", "Political2", "Realistic2", "Romance2", "Saga2", "Satire2", "Science-Fiction2", "Slice-Of-Life2", "Speculative2", "Anime2");
if (in_array(vGenre2, $goodGenre2Param)) {
if(vGenre2 == 'AnyGenre2'){}
else{$queryMain .= " AND ( videoinformation.vidZanr ='".$_GET['vGenre2']."' OR videoinformation.vidZanr2 ='".$_GET['vGenre2']."' OR videoinformation.vidZanr3 ='".$_GET['vGenre2']."')";}
}
//Video Genre three
$vGenre3 = isset($_GET['vGenre3']) ? $_GET['vGenre3'] : 'ALL';
$goodGenre3Param = array("AnyGenre3", "Action", "Adventure", "Comedy", "Crime", "Faction", "Fantasy", "Historical", "Horror", "Mystery", "Paranoid", "Philosophical", "Political", "Realistic", "Romance", "Saga", "Satire", "Science-Fiction", "Slice-Of-Life", "Speculative", "Anime");
if (in_array($vGenre, $goodGenre3Param)) {
if($vGenre3 == 'AnyGenre3'){}
else{$queryMain .= " AND ( videoinformation.vidZanr ='".$_GET['vGenre3']."' OR videoinformation.vidZanr2 ='".$_GET['vGenre3']."' OR videoinformation.vidZanr3 ='".$_GET['vGenre3']."')";}
}
// Video Years
$vYear = isset($_GET['vYear']) ? $_GET['vYear'] : 'ALL';
$goodYearParam = array("AnyYear", "2014", "2013", "2012", "2011", "2010", "2009", "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000", "1999", "1998", "1997");
if (in_array($vType, $goodYearParam)) {
if($vYear == 'AnyYear'){}
else{$queryMain .= " AND newsvid.vidYear ='".$_GET['vYear']."'";}
}
// Video City
$vCity = isset($_GET['vCity']) ? $_GET['vCity'] : 'ALL';
$goodCityParam = array("AnyCity", "Russian", "England");
if (in_array($vCity, $goodCityParam)) {
if($vCity == 'AnyCity'){}
else{$queryMain .= " AND newsvid.vidCity ='".$_GET['vCity']."'";}
}
//NEW of OLD
$order = isset($_GET['order']) ? $_GET['order'] : 'ALL';
$goodParam = array("NEW", "OLD");
if (in_array($order, $goodParam)) {
if($order == 'NEW'){
$queryMain .= " ORDER BY newsvid.id ASC";
}else if($order == 'OLD'){
$queryMain .= " ORDER BY newsvid.id DESC";
}else{
$queryMain .= " AND videoinformation.vidYear = 2014";
}
}
?>
And this is main page view.php:
<!DOCTYPE lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?php include 'BSH.php' ?>
<link rel="stylesheet" type="text/css" href="CSS/sdvid.css">
<title><?php echo $lang['PAGE_TITLE_MAIN'] ?></title>
</head>
<body>
<?php
include_once 'userPages/check_login_status.php';
include_once 'incIndex/headerTop.php';
include 'connect/con.php';
include_once 'inc/sortOrder.php';
?>
<?php
$sqlPages = "SELECT COUNT(id) FROM newsvid WHERE approved='1'";
$queryPages = mysqli_query($con, $sqlPages);
$row = mysqli_fetch_row($queryPages);
// Here we have the total row count
$rows = $row[0];
// This is the number of results we want displayed per page
$page_rows = 1;
// This tells us the page number of our last page
$last = ceil($rows/$page_rows);
// This makes sure $last cannot be less than 1
if($last < 1){
$last = 1;
}
// Establish the $pagenum variable
$pagenum = 1;
// Get pagenum from URL vars if it is present, else it is = 1
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
// This makes sure the page number isn't below 1, or more than our $last page
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
// This sets the range of rows to query for the chosen $pagenum
$limit = "LIMIT " .($pagenum - 1) * $page_rows ."," .$page_rows;
// This is your query again, it is for grabbing just one page worth of rows by applying $limit
$queryMainList = $queryMain . $limit;
$resultDisplay = mysqli_query($con, $queryMainList);
// This shows the user what page they are on, and the total number of pages
$pagesTitle = "On website <b>$rows</b>";
$pagesOutOf = "Page <b>$pagenum</b> of <b>$last</b>";
// Establish the $paginationCtrls variable
$paginationCtrls = '';
// If there is more than 1 page worth of results
if($last != 1){
/* First we check if we are on page one. If we are then we don't need a link to
the previous page or the first page so we do nothing. If we aren't then we
generate links to the first page, and to the previous page. */
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= 'Previous ';
// Render clickable number links that should appear on the left of the target page number
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= ''.$i.' ';
}
}
}
// Render the target page number, but without it being a link
$paginationCtrls .= ''.$pagenum.' ';
// Render clickable number links that should appear on the right of the target page number
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= ''.$i.' ';
if($i >= $pagenum+4){
break;
}
}
// This does the same as above, only checking if we are on the last page, and then generating the "Next"
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' Next ';
}
}
$list = '';
while($row = mysqli_fetch_array($resultDisplay, MYSQLI_ASSOC)){
$list .= "<div class=\"panel-heading\">
<div><a class=\"panel-title btn-block\" href=\"details.php?id=".$row['id']."\"><h3>".$row['id']." | ".$row['vidTitle']."</h3></a></div>
</div>
<div class=\"panel-body\">
<div class=\"imgCover\"><img class=\"imageCover\"src=\"" . $row['url'] . "\"></div>
<div class=\"vidSD\">" . $row['vidSD'] . "</div>
<div class=\"vidDetails\">
<hr class=\"style-two\">
<table>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtYear'] . "</strong></td><td class=\"vidDetailsTD\">" . $row['vidYear'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtCity'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidCity'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtGenre'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidZanr'] ." , ". $row['vidZanr2'] ." , ". $row['vidZanr3'] . "</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtQuality'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidQuality'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtTranslatedBy'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidTranslated'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtVideoTime'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidTime'] . "</td></tr>
</table>
</div></div>
<div class=\"panel-footer\">
<h6><strong>" . $lang['vsdAuthor'] . "</strong>".$row['addName']."</h6>
<div><h6><strong>" . $lang['vsdPublished'] . "</strong>" . $row['published'] . "</h6></div>
</div>";
}
mysqli_close($con);
?>
<div class="mainLeftCover">
<form action="view.php" method="GET">
<div class="input-group" style="width:180px">
<span class="input-group-addon" style="width:65px"><?php echo $lang['vidOrderTitleNew'] ?></span>
<select class="form-control" name = "order">
<option value="NEW">NEW</option>
<option value="OLD">OLD</option>
</select>
</div>
<?php
include_once 'inc/sortInc/sortType.php';
include_once 'inc/sortInc/sortGenre.php';
include_once 'inc/sortInc/sortGenre2.php';
include_once 'inc/sortInc/sortGenre3.php';
include_once 'inc/sortInc/sortYear.php';
include_once 'inc/sortInc/sortCity.php';
?>
<br><button type="submit" class="btn btn-default" style="width:180px">Submit</button>
</form>
<?php echo" <div id=\"pagination_controls\">" .$paginationCtrls. "</div>"; ?>
</div>
<?php
echo "<div class=\"maincover \" data-role=\"scrollbox\" data-scroll=\"vertical\">";
echo "<div class=\"panel panel-default\">";
echo" <div style=\"background-color:#fff\">" .$list. "</div>";
echo "</div></div>";
?>
Just for encase I gave full code. The problem is, that PAGINATION on it's own working fine... And ORDER function working fine separately as well. BUT TOGETHER they do not want to work. As result I have working pagination and if try to use sort it's just become empty page.
What I need..is somehow make sorting method working with pagination together, but i'm stuck how to do it.
I have this url when I'm using pagination:
http://example.net/view.php?pn=3
And this one when I'm using order:
http://example.net/view.php?order=NEW&vType=Film&vGenre=AnyGenre1&vGenre2=AnyGenre2&vGenre3=AnyGenre3&vYear=AnyYear&vCity=AnyCity
AND I need that URL will be like this:
http://example.net/view.php?pn=3&order=NEW&vType=Film&vGenre=AnyGenre1&vGenre2=AnyGenre2&vGenre3=AnyGenre3&vYear=AnyYear&vCity=AnyCity
That if you sort the page... it will remember how user was sort the list and open pages (pn=1, pn=2) will change.
May be some how save sort result and then use it in pagination..need to save it maybe when submit button pressed? But how can I save result from user???
<?php
session_start();
include_once 'dbconnect.php';
?>
<?php include ('head.php') ; ?>
<?php include ('menu.php') ; ?>
<?php if (isset($_SESSION['usr_id'])) { ?>
<?
$per_page = 15;
if (isset($_GET["page"])) {$page = $_GET["page"];}else {$page = 1;}
if (isset($_GET["order"])) {$order = $_GET["order"];}else {$order = username;}
$start_from = ($page-1) * $per_page;
if(isset($_GET['order']) && $_GET['order'] == 'user_id'){
$query = "select * from users order by user_id DESC limit $start_from, $per_page";}
if(isset($_GET['order']) && $_GET['order'] == 'username'){
$query = "select * from users order by username ASC limit $start_from, $per_page";}
if(isset($_GET['order']) && $_GET['order'] == 'posts'){
$query = "select * from users order by posts DESC limit $start_from, $per_page";}
$result = mysqli_query ($DBcon, $query);
$user_list_result = $DBcon->query("select * from users order by $order ASC limit 100");
$session = $_SESSION['usr_name'];
$query = $DBcon->query("SELECT * FROM users WHERE username='$session'");
$userRow=$query->fetch_array();
if ($userRow['userlevel'] > 0) {
?>
<div class="container">
<div class="row">
<div class="col-lg-6 col-sm-12">
<div class="panel panel-default panel-compact panel-wallet">
<div class="panel-body">
<center><h1>Userlist </h1></center>
<center>
<table >
<tr> <td width="20%"><b>ID </b></td>
<td width="20%"><b>Nickname </b></td>
<td width="20%"><b>Posts </b></td>
<td width="20%"><b>Message </b></td>
<td width="20%"><b>Click </b></td> </tr>
<?php
while($UserlistRow = $result->fetch_array())
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td>
<td>$UserlistRow[posts]</td>
</center>
<td><a href=msg_send.php?to=$UserlistRow[username]>Send Message</a></td>
<td><a href=user_click.php?to=$UserlistRow[username]>Click</a></td> ";?>
</tr>
<?php } ?> </table>
</center>
<?
$query = "select * from users order by $order";
$result = mysqli_query($DBcon, $query);
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / $per_page);
echo "<a href='user_list.php?page=" . ($_GET['page']+1) . "&order=" . ($_GET['order']) . "'>Next Page</a>";
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='user_list.php?page=".$i."&order=" . ($_GET['order']) . "'>".$i."</a> ";
};
echo "<a href='user_list.php?page=" . ($_GET['page']-1) . "&order=" . ($_GET['order']) . "'>Previous Page</a>";
?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } else { include('login_frame.php'); } ?>
<?php include ('footer.php') ; ?>