summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2011-11-24 21:24:36 -0800
committerArun Persaud <apersaud@lbl.gov>2011-11-24 21:39:56 -0800
commit4849d7271c75cace9faffc1353c22101b84c49bb (patch)
tree4fa9f9c3decd3991be63078b3e8b753ebce60f32
parent9d77827195a8057746842bfa307d550d04ed02f9 (diff)
downloadphoto-tags-4849d7271c75cace9faffc1353c22101b84c49bb.tar.gz
photo-tags-4849d7271c75cace9faffc1353c22101b84c49bb.tar.bz2
photo-tags-4849d7271c75cace9faffc1353c22101b84c49bb.zip
add a basic index of all pages...
need to restrict this still to not show all, e.g. add first and last button to next and prev and only show a few page links
-rw-r--r--getjson.php49
-rw-r--r--index.php13
-rw-r--r--style.css13
3 files changed, 51 insertions, 24 deletions
diff --git a/getjson.php b/getjson.php
index b220544..0b414be 100644
--- a/getjson.php
+++ b/getjson.php
@@ -9,40 +9,46 @@ $usePDO=$iniarray["usePDO"];
$N=$iniarray["pics_per_page"];
/* end parse ini-file */
-if (isset($_REQUEST["P"]))
- $OFFSET = "".($_REQUEST["P"]*$N-$N).",";
-else
- $OFFSET = "";
-
if($usePDO)
$DB = new PDO("sqlite:$DBFILE");
else
$DB = new SQlite3($DBFILE);
-$result = $DB->query("SELECT * FROM photos LIMIT $OFFSET $N");
-$row = array();
+/* do database query */
+if (isset($_REQUEST["P"]))
+ {
+ $OFFSET = "".($_REQUEST["P"]*$N-$N);
-$i = 0;
+ $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N");
+ }
+else if (isset($_REQUEST["T"]))
+ {
+ $result = $DB->query("SELECT count(*) as total FROM photos");
+ }
+else
+ $result=null;
+/* encode result as an array */
+$tmp=array();
if(!$usePDO)
{
/* convert results into array */
- $tmp=array();
- while($res = $result->fetchArray(SQLITE3_ASSOC)){
- $tmp[]=$res;
- }
- $result=$tmp;
+ while($res = $result->fetchArray(SQLITE3_ASSOC))
+ {
+ $tmp[]=$res;
+ }
}
+else
+ {
+ foreach($result as $res)
+ {
+ $tmp[]=$res;
+ }
+ }
+$result=$tmp;
-foreach ($result as $res)
-{
- $row[$i] = $res;
- $i++;
-}
-
-
-echo json_encode($row);
+echo json_encode($result);
/* close the database */
if($usePDO)
@@ -50,5 +56,6 @@ if($usePDO)
else
$DB->close();
+
?>
diff --git a/index.php b/index.php
index 5f04543..018bedd 100644
--- a/index.php
+++ b/index.php
@@ -30,7 +30,7 @@ else
<button class="next" onclick="right()">next </button>
<div class="permalink"></div>
-
+<div class="index"></div>
<div class="pics"> </div>
<footer>
@@ -49,6 +49,15 @@ var N=<?php echo $N ?>;
var count=0;
function myreload(a) {
+ d3.json("<?php echo $webbase?>/getjson.php?T=1", function(json) {
+ s="page ";
+ n = json[0].total/N;
+ for(i=1;i<=n+1;i++)
+ {
+ s+=" <a href=\"<?php echo $webbase?>/page/"+i+"\">"+i+"</a>";
+ }
+ d3.select(".index").html(s);
+ });
d3.json("<?php echo $webbase?>/getjson.php?P="+a, function(json) {
count=0;
pics.selectAll("li").remove();
@@ -72,7 +81,7 @@ function myreload(a) {
permalink="<?php echo $webbase ?>/page/"+page;
d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
- d3.select(".debug").text("P, count= "+a+" "+count);
+ d3.select(".debug").text("P,N ="+a+" "+N);
}
function left() {
diff --git a/style.css b/style.css
index b394c6c..6c25246 100644
--- a/style.css
+++ b/style.css
@@ -1,6 +1,9 @@
h1 {color:red}
-body {background-color: black}
+body {
+ background-color: black;
+ color: #eee;
+}
.permalink {
float:right;
@@ -10,6 +13,11 @@ body {background-color: black}
a[visited]{ color: #aaa;}
+.index {
+ margin: 0 auto;
+ width:70%;
+}
+
.pics li {
display: inline;
list-style: none;
@@ -30,3 +38,6 @@ footer {
color: #999;
float:right;
}
+
+
+.debug { position: absolute; top:0; left:0} \ No newline at end of file