diff options
author | Remi Collet <fedora@famillecollet.com> | 2014-07-27 18:56:35 +0200 |
---|---|---|
committer | Remi Collet <fedora@famillecollet.com> | 2014-07-27 18:56:35 +0200 |
commit | 28426e876a043bcc0cfdbc52412d1da482305746 (patch) | |
tree | 61e026e13b2b7db4df0e0f48e97931e7b4381102 | |
parent | a30604293878c9cf4794c00d289442f9e0a20311 (diff) |
search for composer name in autocompleter
-rw-r--r-- | autocompleter.php | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/autocompleter.php b/autocompleter.php index 38e9d4e..d27601d 100644 --- a/autocompleter.php +++ b/autocompleter.php @@ -42,11 +42,11 @@ $ret = null; if ( !isset($_GET['q']) || $_GET['q'] == '' ) { die(); } else { - $q = $_GET['q']; + $q = addslashes($_GET['q']); if ( !isset($_GET['limit']) || $_GET['limit'] == '' ) { $limit = 10; } else { - $limit = $_GET['limit']; + $limit = intval($_GET['limit']); } } @@ -54,11 +54,19 @@ try { $db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS); $sql = "SELECT name FROM rpm WHERE name LIKE '$q%' GROUP BY name LIMIT 0,$limit"; - $resrpm = $db->query($sql); while ( $rpm = $resrpm->fetchObject() ) { $ret .= $rpm->name . "\n"; + $limit--; + } + if ($limit) { + $sql = "SELECT rpmname FROM packagist WHERE pkgname LIKE '$q%' LIMIT 0,$limit"; + $resrpm = $db->query($sql); + + while ( $rpm = $resrpm->fetchObject() ) { + $ret .= $rpm->rpmname . "\n"; + } } } catch(PDOException $e) { echo 'An error occured.'; |