Created
December 18, 2012 13:07
-
-
Save cfjedimaster/4327849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
remote function getData(numeric page=1) { | |
var start = (arguments.page-1)*10+1; | |
if(start < 1 || round(start) neq start) start=1; | |
//force json | |
url.returnformat="json"; | |
var q = new query(); | |
q.setDatasource("blog"); | |
q.setSQL("select title from tblblogentries limit #start-1#,10"); | |
var queryResult = q.execute().getResult(); | |
var result = {"total"=getTotal(),"titles"=[]}; | |
for(var i=1; i<queryResult.recordCount; i++) arrayAppend(result.titles, queryResult.title[i]); | |
return result; | |
} | |
private function getTotal() { | |
var total = cacheGet("total"); | |
if(isNull(total)) { | |
var q = new query(); | |
q.setDatasource("blog"); | |
q.setSQL("select count(0) as total from tblblogentries"); | |
var total = q.execute().getResult().total; | |
cachePut("total", total); | |
} | |
return total; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment