Limit Pagination (1 2 3 4 5 .. 30 31 32 33) - php

I have a system in php, ajax and jquery. This system will search the database queries per page 5 and divide the results into several pages. The problem is that the more the results are more pages are displayed. In the current code, paging is like this: first 1 2 3 4 5 6 last. I would like to remain so: first 1 2 ... 5 6 last. Ie I want to limit the pagination. If I do not limit the pagination when they have more results would look like this: 1234567891011 ...
The code:
<script type="text/javascript">
$(document).ready(function(){
function showLoader(){
$('.search-background').fadeIn(200);
}
function hideLoader(){
$('.search-background').fadeOut(200);
};
$(".pagcon li").click(function(){
showLoader();
$(".pagcon li").removeClass('current');
$(this).addClass("current");
$("#resultado").load("data.php?page=" + this.id, hideLoader)
return false;
});
$("#1").addClass("current");
showLoader();
$("#resultado").load("data.php?page=1", hideLoader);
});
</script>
<style type="text/css">
#consultas {
width:780px;
min-height:245px;
overflow:hidden;
}
.search-background {
background:#FFF;
display:none;
height:154px;
position:absolute;
padding-top:84px;
text-align:center;
opacity:0.5;
filter:alpha(opacity=50);
width:780px;
z-index:999;
}
</style>
<div id="consultas">
<?php
$per_page = 5;
$sql = "select * from consultas ";
$rsd = mysql_query($sql);
$count = mysql_num_rows($rsd);
$pages = ceil($count/$per_page);
?>
<div class="search-background">
<label><img title="Carregando..." src="loader.gif" alt="" /></label>
</div>
<div id="resultado">
</div>
</div>
<ul class="pagination clearfix pagcon">
<?php
//Show page links
echo '<li id="1"><a title="Página 1" href="#">Primeiro</a></li>';
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
echo '<li id="'.$pages.'"><a title="Página '.$pages.'" href="#">Último</a></li>';
?>
</ul>
data.php:
<?php
include_once("config.php"); //MYSQL CONFIG
$per_page = 5;
$sqlc = "show columns from consultas";
$rsdc = mysql_query($sqlc);
$cols = mysql_num_rows($rsdc);
$page = $_REQUEST['page'];
$start = ($page-1)*5;
$sql = "select * from consultas ORDER BY data DESC LIMIT $start,5";
$rsd = mysql_query($sql);
?>
<?php
while ($rows = mysql_fetch_assoc($rsd))
{?>
<div class="message status success">
<span><b><?php echo $rows['consulta']; ?> (<font color="#8D4B19"><?php echo $rows['codigo']; ?></font>)</b></span>
<span><?php if(strlen($rows['user']) >= 30){ echo substr($rows['user'], 0, 30)."..."; } else { echo $rows['user']; } ?></span>
<span><b><?php echo $rows['operacao']; ?></b></span>
<span><?php echo date("d/m/Y", strtotime($rows['data'])); ?></span>
<span>R$ <?php echo $rows['valor']; ?></span>
</div>
<?php
}?>
<script type="text/javascript">
$(document).ready(function(){
var Timer = '';
var selecter = 0;
var Main =0;
bring(selecter);
});
function bring ( selecter )
{
$('div.status:eq(' + selecter + ')').stop().animate({ opacity: '1.0', height: '34px' },300,function(){
if(selecter < 6)
{
$('div.status').stop().animate({ opacity: '1.0', height: '17px' },300);
clearTimeout(Timer);
}
});
selecter++;
var Func = function(){ bring(selecter); };
Timer = setTimeout(Func, 20);
}
</script>

Try
$threshold=1;
for($i=1; $i<=$threshold+1; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
echo " ... ";
for($i=$pages-$threshold; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
By varying $threshold you can vary the number of page links available.
However, it would be better to present the results as first ... 3 4 5 ... last instead if the user is on the fourth page. This way they can easily move between adjacent pages. Also you can run through the loop fewer times. $current_page is the current page you are on. This needs to be made available to the pagination code somehow.
$threshold=1;
$lower_limit=(($current_page-$threshold)>1)?$current_page-$threshold:1;
$upper_limit=(($current_page+$threshold)<$pages)?$current_page-$threshold:$pages;
for($i=$lower_limit; $i<=$upper_limit; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
Edit for the sake of this specific question
Your pagination is once and not reloaded in the ajax. In order to achieve this reduced pagination, you either need to
load only a few link elements as in either of the choices above and add new link elements or
load all the link elements but hide unnecessary links until they are required.
For the latter:
php
$threshold=1;
for($i=1; $i<=$threshold+1; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
echo " ... ";
for($i; $i<=$pages; $i++)
{
echo '<li id="'.$i.'"'.($i<($pages-$threshold)?'style="display:none"':'')'>'.$i.'</li>';
}
javascript
$(".pagcon li").click(function(){
showLoader();
$(".pagcon li").hide();//hide all links
$(".pagcon li").removeClass('current');
$(this).addClass("current").show();
var id=parse_int($(this).attr(id));
$(".pagcon li:first, .pagcon li:first, .pagcon li#"+(id-1)+" .pagcon li#"+(id+1)).show();//show adjacent links and 'First' and 'Last'
$("#resultado").load("data.php?page=" + this.id, hideLoader)
return false;
});

Related

Ajax Request to load next piece of data in php loop

I am loading the latest news article to my home page, I would like to load the next one on click of a button. However I get this error on click: home.php:353 Uncaught ReferenceError: nextNews is not defined. The code I have written will load another article but will not hide the previous one. Any suggestions for this are also welcome.
<script>
$( document ).ready(function() {
var newsCount = 1;
function nextNews(item){
newsCount = newsCount + 1;
$("#newsHome2").load("load-news.php", {
newsNewCount: newsCount
});
}
});
</script>
<?php
$query = $handler->query('SELECT * FROM articles LIMIT 1');
$results = $query->fetchAll(PDO::FETCH_ASSOC);
if ($_GET['sort'] == 'dateTime')
{
$sql = " ORDER BY dateTime";}
for ($i=0; $i < count($results); $i++) {
echo '<div class="col-lg-6 col-xs-12 col-sm-12 height-news82" id="newsHome2">';
echo '<h2 class="ashu">Lastest News</h2><br>';
echo '<p class="news-title78">'.$results[$i]['headline'].' <br>'.'</p>';
echo '<img class="news-img33" src="data:image/png;base64,' .base64_encode( $results[$i]['logo'] ).'"/>';
echo '<p class="news-time">'.$results[$i]['dateTime'].'< br>'.'</p>';
echo '<p class="news-body56">'.$results[$i]['text'].'</p>' ;
echo '</p><br><button id="solo-buttons67">Read More</button>';
echo '<i id="arrow20" class="fa fa-chevron-left fa-1x"></ i><i id="arrow21" onclick="nextNews(this)" class="fa fa-chevron-right fa-1x"></i></div>';
}
?>
Your function 'nextNews' is defined in the anonymous function passed to .ready(). So it can't be called in your html.
Alternative:
Use jquery click event
Define the function outside of the anonymous function
Try this workout Its working fine :)
view file view.php
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<div id="newsHome2"></div>
<script type="text/javascript">
var newsCount = 1;
$( document ).ready(function() {
nextNews(newsCount)
});
function nextNews(newsCount){
newsCount = newsCount + 1;
$.post("load-news.php", { newsNewCount: newsCount }, function(data, status){
$("#newsHome2").html(data);
});
}
</script>
php file load-news.php
<?php
if(isset($_POST['newsNewCount'])) { $newsCount=$_POST['newsNewCount']; } else { $newsCount=1; }
echo '<div class="col-lg-6 col-xs-12 col-sm-12 height-news82" id="newsHome2">';
echo '<h2 class="ashu">Lastest News</h2><br>';
echo '<p class="news-title78">headline '.$newsCount.' <br>'.'</p>';
echo '<img class="news-img33" src="data:image/png;base64,"/>';
echo '<p class="news-time">dateTime '.$newsCount.'< br>'.'</p>';
echo '<p class="news-body56">text '.$newsCount.'</p>' ;
echo '</p><br><button id="solo-buttons67">Read More '.$newsCount.'</button>';
echo '<i id="arrow20" class="fa fa-chevron-left fa-1x"></ i><i id="arrow21" onclick="nextNews('.$newsCount.')" class="fa fa-chevron-right fa-1x"> click here for next </i></div>';
?>

How to make visible all my videos with pagination in my Ziggeo application?

So I need some help from a Ziggeo user. I have registered 8 videos in my ziggeo server and now I want to display them in pages divided by 2 videos per page.
Here is what I wrote, but unfortunately it doesn't show me any video, but the compiler doesn't say any error.
<?php include('./ziggeo/pagination.class.php');?>
<?php $myvideos = $ziggeo->videos();
$myarray = array($myvideos);?>
<div class="gallery">
<?php if(count($myarray)){
$pagination = new pagination($myarray, (isset($_GET['page'])?$_GET['page']:1), 3);
$videos = $pagination->getResults();
if(count($videos)!=0) {
echo $pageNumbers = '<h2>'.$pagination->getLinks().'</h2>';
foreach ($videos as $video) {?>
<div class="wall-of-videos-container">
<ziggeo ziggeo-video="<?= $video->token ?>"
ziggeo-width=320 ziggeo-height=240 ziggeo-popup> </ziggeo>
<?= date("Y-m-d h:i a", $video->created) ?>
·<?= $video->duration ?> seconds</div>
<? } echo $pageNumbers; } } ?>
</div><!-- End Gallery -->
I included all the files needed for the Ziggeo configuration.
Who can help me? Thank a lot!
Without seeing 'pagination.class.php' file contents and the output that you are creating it is difficult to know what went wrong, however to create pagination in PHP using Ziggeo PHP SDK, you would do something like this:
<?php
require_once('Ziggeo.php');
$ziggeo = new Ziggeo('YOUR TOKEN', 'YOUR PRIVATE KEY', 'YOUR ENCRYPTION KEY');
?>
You can get the token and keys from your dashboard on ziggeo.com
Ziggeo.php can be retrieved from Ziggeo PHP SDK here: github.com/Ziggeo/ZiggeoPhpSdk
Now looking at your code it seems that this is the call that you are not making correctly. To get the videos you should make the following call:
<?php $myvideos = $ziggeo->videos()->index(); ?>
It is good to remember that by default you will only get up to 50 videos, so if you are expecting to have more than that, you should set the limit parameter.
You can set limit, skip, reverse, states and tags
In case you want to get up to 100 videos (which is maximum per call) you would do something like this:
<?php
$myArguments = array('limit' => 100);
$myvideos = $ziggeo->videos()->index($myArguments);
?>
Now to list them, you would do something like this:
<?php
foreach ($myvideos as $video) {
?>
<ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>
<?php
}
?>
You could add a check with count($myvideos) before foreach, however it should not be needed.
In general, to create a page with 2 videos per page you could use something like this:
<?php
$i = 0; //to have two videos per page
$j = 0; //to see how many we have
foreach ($myvideos as $video) {
$j++;
if($i === 0) { ?>
<div class="gallery_page">
<?php } ?>
<ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>
<?php
$i++;
if($i === 2) { ?>
</div>
<div class="page_number"><?php echo $j/2; ?> </div>
<?php
$i = 0;
}
}
if($i !== 0) {
?>
<div class="page_number"><?php echo (($j-1)/2)+1; ?> </div>
<?php
}
?>
It is good to point out that the above code is not a complete paging system - it is just a simple sample that shows you how you could do it, however it would need to be customized and worked upon further to match gallery style, and similar.
Looking at your code, I think that it should work using something like this:
<?php
include('./ziggeo/pagination.class.php');
$myvideos = $ziggeo->videos()->index();
?>
<div class="gallery">
<?php
if(count($myvideos)) {
$pagination = new pagination($myarray, (isset($_GET['page']) ? $_GET['page']:1), 3);
$videos = $pagination->getResults();
if(count($videos)!=0) {
echo $pageNumbers = '<h2>'.$pagination->getLinks().'</h2>';
foreach ($videos as $video) { ?>
<div class="wall-of-videos-container">
<ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>
<?php echo date("Y-m-d h:i a", $video->created); ?>
·<?php echo $video->duration; ?> seconds</div>
<?php } echo $pageNumbers;
}
} ?>
</div><!-- End Gallery -->
I did presume however that you have the headers set in the HTML HEAD of the page where the gallery will be shown:
<link rel="stylesheet" href="//assets-cdn.ziggeo.com/v1-latest/ziggeo.css" />
<script src="//assets-cdn.ziggeo.com/v1-latest/ziggeo.js"></script>
<script type="text/javascript">ZiggeoApi.token="YOUR TOKEN"</script>
If not present, the HTML code will be created from the above PHP code, however your videos would not be shown due to Ziggeo framework not being loaded on client side.
UPDATE (2016/05/31)
As the above is just general way to do this, it is not including CSS nor JavaScript.
As such I am adding the full code that can be used and as it shows another way to collect the page numbers and leaving the above so that someone can see both.
<script type="text/javascript">
//Basic code needed to switch pages
var currentPage = 1;
function showPage(number) {
//If we are on the same page as the selected one, we just break away from the function, so that we do not hide the same.
if(currentPage === number) { return false; }
var toShow = document.getElementById('page_' + number);
var toHide = document.getElementById('page_' + currentPage);
toShow.style.display = 'block';
toHide.style.display = 'none';
currentPage = number;
}
</script>
<style type="text/css">
/* Code to hide the pages (all) and show first one only, as well as a bit of styling so that it has some basic frame */
.gallery_page > ziggeo {
float: left;
}
.gallery_page {
background-image: linear-gradient(-45deg, lightGray, white);
border-radius: 10px;
box-shadow: 0 0 2px gray;
box-sizing: border-box;
display: none;
min-height: 400px;
margin: 20px 0;
padding: 40px;
width: 720px;
}
.gallery_page:first-child {
display: block;
}
.page_number {
box-shadow: 0 0 3px gray;
float: left;
margin: 0 4px;
text-align: center;
width: 2em;
}
</style>
<div class="gallery">
<?php
//How many videos per page do we want to have?
$numberOfVideos = 2;
//How many videos was there in total?
$totalNumberOfVideos = 0; //only if we need it for something later on
//How many videos are approved / are shown
$totalNumberOfApprovedVideos = 0; //only if we need it for something later on
//which page are we working on?
$currentPage = 1;
//Will serve as buffer for page number elements
$pageNumbers = '';
//temporary videos counter
$i = 0;
foreach ($myvideos as $video) {
//to only show approved videos
if($video->approved === true) {
if($i === 0) { ?>
<div class="gallery_page" id="page_<?php echo $currentPage; ?>">
<?php } ?>
<ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>
<?php
$i++;
if($i === $numberOfVideos) { ?>
<br style="float:none; clear:left;">
</div>
<?php
$pageNumbers .= '<div onclick="showPage(' . $currentPage . ');" class="page_number">' . $currentPage . '</div>';
$currentPage++;
$i = 0;
}
$totalNumberOfApprovedVideos++;
$totalNumberOfVideos++;
}
else {
//$video->moderation_reason
//If you want to check if there was a reason why the video was not approved, you can check the above, or alternatively, you could do something else at this point.
$totalNumberOfVideos++;
}
}
if($i !== 0) {
$pageNumbers .= '<div onclick="showPage(' . $currentPage . ')" class="page_number">' . $currentPage . '</div>';
}
?>
</div><!-- End Gallery -->
<?php echo $pageNumbers; ?>
<?php
//This is not needed for pagination to work, however you might want to show it, etc
echo '<br><br>';
echo 'Approved videos: ' . $totalNumberOfApprovedVideos . '<br>';
echo 'Total videos: ' . $totalNumberOfVideos . '<br>';
echo 'Total number of pages: ' . $currentPage . '<br>';
echo $numberOfVideos . ' videos per page<br>';
?>
It is good to point out that this is just a framework - so the code mentioned before will work just as the followup code does, however both require additional styling and code to make it look nice and behave as we want it.
After adding the java script below:
<script type="text/javascript">
var currentPage = 1;
function showPage(number){
var toShow = document.getElementById('page_' + number);
var toHide = document.getElementById('page_' + currentPage);
toShow.style.display = 'block';
toHide.style.display = 'none';
currentPage = number;}
</script>
And the right references to the div gallery, now all is working. Thanks Bane.

Fancybox only works after second click

So I have a table where each cell is a name of a game and when you click it it needs to show in a fancybox the results of the user which clicked the cell (I use table Indexes to get the GameID and the Session variable to get userID) which will be used to load the results from a second PHP page.
If I click on a cell for the first time the fancybox will not display anything and after I close fancybox and click on any cell again it works fine. Am I doing something wrong?
This is the whole javascript:
$(".jogos").fancybox({
'hideOnContentClick': true,
'onComplete':function(element)
{
var gameIdx = $(element).index();
var cateIdx = $(element).parent().parent().index();
var gameIdxPHP;
var catIdxPHP;
var gameID;
var userId = '<?php echo $_SESSION['userID']; ?>'
<?php
for ($i=1; $i<= count($categoryArray);$i++)
{
for ($j=1; $j<=count($categoryArray[$i-1]->gamelist);$j++)
{
?>
catIdxPHP = '<?php echo $i ?>' -1;
gameIdxPHP = '<?php echo $j ?>' -1;
if (catIdxPHP == cateIdx && gameIdxPHP == gameIdx)
{
gameID = '<?php echo $categoryArray[$i-1]->gamelist[$j-1]->GameID; ?>';
$("#graphic").load("backoffice/resUserNivel2short.php", {userId:userId,gameID:gameID}, function(){ });
}
<?php
}
}
?>
}
});
HTML
<div style="display:none">
<div id="data">
<div id="graphic">
</div>
</div>
</div>
Sample code of the link
<a href="#data" class="jogos" id="cat<?php echo $i; ?>jogo<?php echo $j; ?>" >
You have display:none on the parent of your fancybox therefor the grafic isnt displayed.
The Grafic element isn't inside the dom yet if you use display:none initially. Try to use clip: rect instead as a class and add/remove that class using the fancybox callbacks.
Try this code:
$('.jogos').fancybox({
'onStart': function() {
$("#data").removeClass('hidden');
},
'onClosed': function() {
$("#data").addClass('hidden');
}
});
CSS:
.hidden {
clip: rect(1px 1px 1px 1px);
position: absolute;
)}
HTML:
<div>
<div id="data" class="hidden">
<div id="graphic">
</div>
</div>
</div>

How to dynamically display MySQL data using jQuery and PHP?

I have a PHP page that lists a bunch of words that it grabs from a MySQL database table. It displays the words in different sizes based on a count in the table:
<?php
$selectStr = "select * from test";
if ($results = MySQL($dbName, $selectStr))
{
$rowCount = MySQL_NUMROWS($results);
}
$i = 0;
while ($i < $rowCount)
{
echo '<div style="float: left; font-size:' . (MySQL_RESULT($results,$i,'count') * 5) . 'px;">' . MySQL_RESULT($results,$i,'word') . '</div>';
$i++;
}
?>
The trick is that I want the content to display dynamically. So if a user is sitting on the page, and one of the word counts goes up, I want the word to change size without the user refreshing the page.
I am a novice with jQuery. I have used it a bit before, but only using examples. Can someone steer me in a good direction to have my page dynamically change the content without refreshing?
You can auto refresh your page body like this ... give body id='body'
<html>
<head>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#body').load('wordscount.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
</script>
</head>
<body>
<div id='content'></div>
</body>
Dont forget to include jquery inside your head tag
It calls the file rowfunctie.php every 30000ms and fills the topbar diff with with the result of the getRows function.
<div id="center-rows">
<div id="links">Nu </div>
<div id="rows">
<div id="topbar"></div>
</div>
<div id="rechts"> aantal rijen</div>
</div>
<script type="text/javascript">
function doRequest() {
jQuery("#topbar").fadeOut('slow', function() {
jQuery.ajax({
type: "GET",
url: "rowfunctie.php",
cache: false,
success: function(html){
jQuery("#topbar").html(html);
jQuery("#topbar").fadeIn('slow',function() {
setTimeout('doRequest()',30000);
});
}
});
});
}
doRequest();
</script>
rowfunctie.php should look like this beneath:
<?php
$selectStr = "select * from test";
if ($results = MySQL($dbName, $selectStr))
{
$rowCount = MySQL_NUMROWS($results);
}
$i = 0;
while ($i < $rowCount)
{
echo '<div style="float: left; font-size:' . (MySQL_RESULT($results,$i,'count') * 5) . 'px;">' . MySQL_RESULT($results,$i,'word') . '</div>';
$i++;
}
?>

Fetch new MySQL entries and append to existing div's dynamically

I have a PHP script to selected records for comments from a database, and then print them onto the page. What I'd like to happen is that if a user is on a page, and another user comments on an item on said page, it automatically appends the new comment to the bottom. The problem I'm having is that I don't know how to differentiate between all of the statuses.
My code for generating the comments on a status is:
<?php
$rt = ("SELECT * FROM (SELECT comment as comment, byuid as byuid, comuid as comuid, likes as likes, dislikes as dislikes, UNIX_TIMESTAMP(timestamp) as timestamp FROM mingle_comments WHERE onuid = '$sid' AND type = 'status' ORDER BY timestamp DESC LIMIT 2) mingle_comments ORDER BY timestamp ASC"); //query
$result = mysql_query($rt) or die (mysql_error());
if(mysql_num_rows($result) >= 2) {
?>
<div id="sa" style="background:#E0E0E0; padding:5px 5px 5px 5px;">
View all comments...
</div>
<?php
}
while($st = mysql_fetch_assoc($result)) {
$comment = nl2br($st['comment']);
$by = $st['byuid'];
$comuid = $st['comuid'];
$time = $st['timestamp'];
$l = $st['likes'];
$d = $st['dislikes'];
$bq = "SELECT * FROM users WHERE uid = '$by' LIMIT 1";
$bqq = mysql_query($bq) or die (mysql_error());
while($bqr = mysql_fetch_assoc($bqq)) {
$dp = $bqr['dp'];
$fbq = $bqr['fname'];
$sbq = $bqr['sname'];
}
?>
<div id="commentbox" class="<?php echo $comuid; ?>" style="padding:5px 5px 5px 5px;">
<div id="cbi" style=" display:inline; position:relative; ">
<img src="<?php if ($dp == null) { echo 'img/unknown_user.jpg'; } else { echo "pf/" . $by . "/" . $dp; } ?>" width="36px" style=" display:inline; position:relative;"/>
</div>
<div id="cbt" style="position:relative; margin-left:32px; margin-top:-35px;">
<?php echo $fbq . " " . $sbq; ?>
<p class="<?php echo $comuid; ?>" style="position:relative; margin-left:5px;"><?php echo $comment; ?></p>
</div>
<div id="clb" style="background:#E0E0E0; padding-left:5px;">
Like<?php echo time_since($time); ?>
</div>
</div>
<?php
}
?>
TL:DR; How can I automatically fetch new comments and append them to the comments generated in the above script without page refresh.
JQUERY
$(document).ready(function(){
var lastcheck='';
setInterval(function() {
$.ajax({
url: 'URL_TO_PHP_SCRIPT',
type: 'POST',
data: {'lastcheck':lastcheck},
success: function(result){
if (result!='nothing_new'){
lastcheck=result.lastcheck /*Update lastcheck*/
var data=result.data;
$.each(data, function(i,val){
//Foreach comment you do what you need, like append, prepend, etc. data[i]."key" to get the value.
});
}
}
});
}, 15000 /* This will check each 15 seconds, you can change it */);
});
PHP SIDE
$lastcheck=$_POST['lastcheck'];
/*
You should add a date field to each new created comment,then filter by "orderby date > $lastcheck" so you get comments since your last check
You get the new comments here
...
...
..
*/
if (!empty($arrayofnewcomments)){
/*The output*/
echo json_encode(array('lastcheck'=>date('Y-m-d H:i:s'),'data'=>$arrayofnewcomments));
}else{/*No new comments*/
echo 'nothing_new';
}
This is some code I came up with, it's a general Idea but it works. It will check each 15 seconds for new comments.

Categories