make number of pictures/page a config option; replace "offset" with "page"
[photo-tags.git] / getjson.php
index cbb9feea559cc144bf756dfb1a89e021e92dd65f..24a913f2977084a472e1e83b1a2d7243e17ab88e 100644 (file)
@@ -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);