diff options
author | Arun Persaud <arun@nubati.net> | 2011-11-24 10:55:09 -0800 |
---|---|---|
committer | Arun Persaud <apersaud@lbl.gov> | 2011-11-24 10:55:09 -0800 |
commit | 01394769937f108ee0f3a8077b34bb5fc9bffe24 (patch) | |
tree | b0c609d377667ecbb7adc29151fd0a3f38760014 | |
parent | 78ab005390d15e706f68d2beabfa0a4ad79e0703 (diff) | |
download | photo-tags-01394769937f108ee0f3a8077b34bb5fc9bffe24.tar.gz photo-tags-01394769937f108ee0f3a8077b34bb5fc9bffe24.tar.bz2 photo-tags-01394769937f108ee0f3a8077b34bb5fc9bffe24.zip |
make number of pictures/page a config option; replace "offset" with "page"
-rw-r--r-- | config.ini_template | 1 | ||||
-rw-r--r-- | getjson.php | 24 | ||||
-rw-r--r-- | index.php | 23 |
3 files changed, 23 insertions, 25 deletions
diff --git a/config.ini_template b/config.ini_template index bdbf94d..387428d 100644 --- a/config.ini_template +++ b/config.ini_template @@ -15,3 +15,4 @@ removemeta=0 webbase="http://localhost/f-spot-gallery" admin="Some One <some.one@example.net>" title="Some One's Gallery" +pics_per_page=30
\ No newline at end of file diff --git a/getjson.php b/getjson.php index cbb9fee..24a913f 100644 --- a/getjson.php +++ b/getjson.php @@ -1,27 +1,25 @@ <?php +$N=30; + /* parse ini -file */ $iniarray=parse_ini_file("config.ini"); $DBFILE=$iniarray["fspotdb"]; $usePDO=$iniarray["usePDO"]; +$N=$iniarray["pics_per_page"]; /* end parse ini-file */ -if (isset($_REQUEST["O"])) - $O = "".$_REQUEST["O"].","; -else - $O=""; - -if (isset($_REQUEST["N"])) - $N = "".$_REQUEST["N"]; +if (isset($_REQUEST["P"])) + $OFFSET = "".($_REQUEST["P"]*$N).","; else - $N= 25; + $OFFSET = ""; if($usePDO) $DB = new PDO("sqlite:$DBFILE"); else $DB = new SQlite3($DBFILE); -$result = $DB->query("SELECT * FROM photos LIMIT $O $N"); +$result = $DB->query("SELECT * FROM photos LIMIT $OFFSET $N"); $row = array(); @@ -37,13 +35,11 @@ if(!$usePDO) $result=$tmp; } -foreach ($result as $res){ - +foreach ($result as $res) +{ $row[$i] = $res; - $i++; - - } +} echo json_encode($row); @@ -5,6 +5,7 @@ $webbase=$iniarray["webbase"]; $dbprefix=$iniarray["dbprefix"]; $admin=$iniarray["admin"]; $title=$iniarray["title"]; +$N=$iniarray["pics_per_page"]; /* end parse ini-file */ ?> <html> @@ -34,12 +35,12 @@ $title=$iniarray["title"]; var pics = d3.select(".pics").append("ul"); -var offset=0; -var N=30; +var page=0; +var N=<?php echo $N?>; var count=0; -function myreload(a,b) { - d3.json("<?php echo $webbase?>/getjson.php?O="+a+"&N="+b, function(json) { +function myreload(a) { + d3.json("<?php echo $webbase?>/getjson.php?P="+a, function(json) { count=0; pics.selectAll("li").remove(); pics.selectAll("li").data(json) @@ -60,22 +61,22 @@ function myreload(a,b) { checkbutton(); }); - d3.select(".debug").text("O, N= "+a+" "+b+" "+count); + d3.select(".debug").text("P, count= "+a+" "+count); } function left() { - if (offset>=N) offset=offset-N; - myreload(offset,N); + if (page>=1) page=page-1; + myreload(page); } function right() { - offset=offset+N; - myreload(offset,N); + page=page+1; + myreload(page); } function checkbutton() { - if (offset==0) + if (page==0) { d3.select("button.prev").attr("disabled","disabled");} else { d3.select("button.prev").attr("disabled", null);}; @@ -86,7 +87,7 @@ function checkbutton() { { d3.select("button.next").attr("disabled",null);} } -myreload(offset,N); +myreload(page); </script> |