6 $iniarray=parse_ini_file("config.ini");
7 $DBFILE=$iniarray["fspotdb"];
8 $usePDO=$iniarray["usePDO"];
9 $N=$iniarray["pics_per_page"];
10 /* end parse ini-file */
13 $DB = new PDO("sqlite:$DBFILE");
15 $DB = new SQlite3($DBFILE);
18 /* do database query */
19 if (isset($_REQUEST["S"]))
21 /* single tag or part of tag */
22 $tag = $_REQUEST["S"];
23 /* individual tags are separated by '+' */
24 $result = $DB->query("SELECT name FROM tags where name like \"%$tag%\"");
25 $count = $DB->query("SELECT 1");
29 if (isset($_REQUEST["P"]))
30 $OFFSET = "".($_REQUEST["P"]*$N-$N);
34 if (isset($_REQUEST["T"]))
36 /* single tag or part of tag */
37 $tags = $_REQUEST["T"];
38 $tags = explode("+",$tags);
39 $tags = "'".implode("','",$tags)."'";
41 /* individual tags are seperated by '+' */
42 $result = $DB->query("SELECT base_uri, filename FROM photos ".
43 " left join photo_tags on photos.id=photo_tags.photo_id ".
44 " left join tags on tags.id=photo_tags.tag_id ".
45 " where tags.name in ($tags) LIMIT $OFFSET, $N");
47 $count = $DB->query("SELECT count(*) as total FROM photos ".
48 " left join photo_tags on photos.id=photo_tags.photo_id ".
49 " left join tags on tags.id=photo_tags.tag_id ".
50 " where tags.name in ($tags)");
55 $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N");
56 $count = $DB->query("SELECT count(*) as total FROM photos");
60 /* encode result as an array */
64 /* convert results into array */
65 while($res = $result->fetchArray(SQLITE3_ASSOC))
70 foreach($result as $res)
75 /* encode count as an array */
79 /* convert results into array */
80 while($res = $count->fetchArray(SQLITE3_ASSOC))
85 foreach($count as $res)
90 $return=array($count,$result);
92 echo json_encode($return);
94 /* close the database */