Skip to content
This repository was archived by the owner on Jul 2, 2018. It is now read-only.

autocomplete dynamic with data pass #108

@lucafrassineti

Description

@lucafrassineti

i have two input field, the first have autocomplete with cities names, I need to set the second field zone, with autocomplete filtered by selected city... i tried this but dont work...

$("#zone").focus(function(){
var c = $('#city').val();
$('#zone').autocomplete({
source: '/auto_q_int.php?city=' + c
});
});

auto_q_int.php is:

class Autocomplete

{
public $term;
public $conn;

    public function __construct()
    {
        $this->dbConnect();
        $this->term = mysql_real_escape_string($_GET['term']);

    }

    private function dbConnect()
    {
        $this->conn = mysql_connect(HOST,USER,PASSWORD) OR die("connection failed");
        mysql_select_db(DB, $this->conn) OR die("no db selected");
    }

    public function printResult()
    {
        $sql = "SELECT zone
        FROM zones
        WHERE zone LIKE '%$this->term%' && id = '$_GET[city]'
        ORDER BY zone ASC";

        $res = mysql_query($sql, $this->conn);

        $return = array();
        $arr = array();

        while($row = mysql_fetch_array($res))
        {
            array_push($return, $arr);
        }

        echo json_encode($return);
    }

}

$autocomplete = new Autocomplete();
$autocomplete->printResult();

some help please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions