summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-10-26 00:39:52 +0200
committerLukas Fleischer <archlinux@cryptocrack.de>2011-11-02 21:21:23 +0100
commit168a51431bda11d2250a26e8acb8b05c0876092e (patch)
treee2aa5509c6e2d37141baa10eb6c788e389aafe0d
parent9415e078a3704b7f42bb2853f58d111e0982a4d3 (diff)
downloadaur-168a51431bda11d2250a26e8acb8b05c0876092e.tar.gz
aur-168a51431bda11d2250a26e8acb8b05c0876092e.tar.xz
aurjson: add result count to JSON result
We already ask for the result count, but only use it as a basis for testing query success or failure. Add the value to the JSON reply. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
-rw-r--r--web/lib/aurjson.class.php11
1 files changed, 6 insertions, 5 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 234a3c43..4b97d2b3 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -103,7 +103,7 @@ class AurJSON {
private function json_error($msg) {
// set content type header to app/json
header('content-type: application/json');
- return $this->json_results('error', $msg);
+ return $this->json_results('error', 0, $msg);
}
/**
@@ -112,8 +112,8 @@ class AurJSON {
* @param $data The result data to return
* @return mixed A json formatted result response.
**/
- private function json_results($type, $data) {
- return json_encode( array('type' => $type, 'results' => $data) );
+ private function json_results($type, $count, $data) {
+ return json_encode( array('type' => $type, 'resultcount' => $count, 'results' => $data) );
}
private function process_query($type, $where_condition) {
@@ -124,7 +124,8 @@ class AurJSON {
"WHERE ${where_condition}";
$result = db_query($query, $this->dbh);
- if ( $result && (mysql_num_rows($result) > 0) ) {
+ $resultcount = mysql_num_rows($result);
+ if ( $result && $resultcount > 0 ) {
$search_data = array();
while ( $row = mysql_fetch_assoc($result) ) {
$name = $row['Name'];
@@ -148,7 +149,7 @@ class AurJSON {
}
mysql_free_result($result);
- return $this->json_results($type, $search_data);
+ return $this->json_results($type, $resultcount, $search_data);
}
else {
return $this->json_error('No results found');