From 4849d7271c75cace9faffc1353c22101b84c49bb Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Thu, 24 Nov 2011 21:24:36 -0800 Subject: 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 --- getjson.php | 49 ++++++++++++++++++++++++++++--------------------- index.php | 13 +++++++++++-- style.css | 13 ++++++++++++- 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 - +