<?php
class autocomplete {
    var $searchquery;
    var $table;
    var $field;
    var $limit;
    var $type;

    function __construct($searchquery, $table, $field, $limit=0, $type='ASC' ) {
        $this->searchquery = $searchquery;
        $this->table = $table;
        $this->field = $field;
        $this->limit = $limit;
        $this->type = $type;
    }

    function getresult() {
        $query = "SELECT " . dbEscapeString($this->field) . " FROM " . dbEscapeString($this->table);
        $query .= " WHERE " . dbEscapeString($this->field) . " LIKE '" . dbEscapeString($this->searchquery) . "%' ";
        $query .= " ORDER BY " . dbEscapeString($this->field) . " ASC ";
        $query .= " LIMIT 0," . dbEscapeString($this->limit);
        $result = dbQuery($query) or
            error("Cannot select " . $this->field . " from " . $this->table);
        $searchresult = '';
        while ($row = dbFetchRow($result)) {
            $searchresult .= $row[dbEscapeString($this->field)] . "\n";
        }
#        dbFreeResult($result);
        return $searchresult;
    }
}
