JQuery Autocomplete, populate with data from pHp json

前端 未结 4 644
鱼传尺愫
鱼传尺愫 2021-01-07 09:39

I am returning a JSON encoded array: echo(json_encode($data)); from php and I would like it to populate the suggest box from JQuery autocomplete. I\'m using thi

4条回答
  •  温柔的废话
    2021-01-07 10:23

    Somthing like this is the best way. json_encode do all work for you.

        $result = $_mysqli->query(...);
        $rs = array();
        $pos = 0;
        while($row = $result->fetch_assoc()){
            $rs[$pos]["n1"] = $row["n1"];
            $rs[$pos]["n2"] = $row["n2"];
            ...
            $rs[$pos++]["nn"] = $row["nn"];
    
        }
        header('Content-type: application/json');
        echo json_encode($rs);
    

提交回复
热议问题