diff options
Diffstat (limited to 'autocompleter.php')
-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.'; |