Skip to main content

PHP/JSON-jquery pagination



I Need away to show two per page, and have a pagination at the bottom of the page.





Here is how I am currently doing it.





As you can see we dont do any pagination at the moment.





PHP code which returns the JSON data







public function realcashoffers($state,$count)

{

$this->state = $state;

$this->number = $count;

$result = $this->JSONselect("approved_business, business_stores, Real_Cash_Offers"," *, group_concat(offer ORDER BY offer ASC SEPARATOR ',') as offers"," approved_business.id = business_stores.business_id AND Real_Cash_Offers.business_id = approved_business.id AND Real_Cash_Offers.storeid = business_stores.storeid AND business_stores.state = '{$this->state}'","GROUP BY id ORDER BY RAND(), approved_business.id DESC LIMIT {$this->number} ");



$remaining = $count - count($result);



if ($remaining) {

$this->type = 'G';

$result = array_merge($result, $this->JSONselect("iNcard_Products","*, productname as tradingname, CONCAT_WS('|', id,'{$this->type}') AS id, CONCAT_WS('|', spend, cashback) AS offer, group_concat(CONCAT_WS('|', spend, cashback) ORDER BY spend ASC SEPARATOR ',') as offers ,picurl as pictureurl","picurl != 'NULL'","GROUP BY productname ORDER BY RAND() LIMIT {$remaining} "));



}



print $this->JSONprint($result);

}







The the jQuery Code







function fetch(e,formstring)

{

var a = 1;

var b = 1;

var rc="";

var spendoffer="";

$.ajax({

type: 'POST',

url: 'http://www.incard.com.au/newsite/system/classes/core.php',

data: formstring,

dataType: 'json',

contentType: "application/x-www-form-urlencoded;charset=utf-8",

beforeSend: function() {

switch (e) {

},

success: function(data){

$.each(data, function(i, obj) {



switch (e) {





//300 OFFERS

case 300:

if(a != 9)

{

$("#title"+a).html(obj.tradingname.toUpperCase());

if(!obj.discription)

{

obj.discription = 'We make sure that all of our customers leave with what they expected and are happy.';

}



if(!obj.pictureurl)

{

obj.pictureurl = 'http://www.incard.com.au/newsite/template/categoryimages/iStock_000008235598Small.jpg';

}

$("#pic"+a).html("<img style='width:180px;' src='"+obj.pictureurl+"'/>");

$("#spend"+a+"_0").html("Spend $"+obj.offers.split('|')[0].replace('.00', '').replace(' $', '')+"<br/><span>Get $"+obj.offers.split('|')[1].split(',')[0].replace(' $', '')+"</span>");

if(obj.offers.split(',')[b])

{



rc = obj.offers.split(',')[b];

spendoffer = rc.split('|');

$("#spend"+a+"_1").append("Spend $"+spendoffer[0].replace('.00', '').replace(' $', '')+" <span>Get $"+spendoffer[1].replace(' $ ', '')+"</span><br/>");

b++;

if(obj.offers.split(',')[b])

{

rc = obj.offers.split(',')[b];

spendoffer = rc.split('|');

$("#spend"+a+"_1").append("Spend $"+spendoffer[0].replace('.00', '').replace(' $', '')+" <span>Get $"+spendoffer[1].replace(' $', '')+"</span><br/>");

}

b++;



if(obj.offers.split(',')[b])

{

rc = obj.offers.split(',')[b];

spendoffer = rc.split('|');

$("#spend"+a+"_1").append("Spend $"+spendoffer[0].replace('.00', '').replace(' $ ', '')+" <span>Get $"+spendoffer[1].replace(' $', '')+"</span><br/>");

}



}

else

{

b = 1;

//$("#spend"+a+"_1").html("More to Come");

}

if(obj.id.split('|')[1] != "G")

{

$("a#link"+a).attr("href", "?page=BusinessOffer&id="+obj.id);

}

else

{

obj.discription = 'Looking for that perfect gift for someone special or for yourself get your '+obj.tradingname+' giftcard.';

$("a#link"+a).attr("href", "?page=GiftCardOffer&id="+obj.id.split('|')[0]);

}

$("#description"+a).html(obj.discription);

national = obj.suburb;

if(!national)

{

national = "National";

}

$("#sub"+a).html(national.toUpperCase());

a++;

}

break;





}

});

},

error: function(data){

$.each(data,function(i,myinfo){



});

},

complete: function(){

switch (e)

{

case 3:

lava();

break;

case 700:



showAddress(businessaddress);

break;

}

},

"text json": jQuery.parseJSON

});

return false;

}




Comments

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex