<?phpheader ("Content-type:text/html;charset=utf-8");//Connect Database $con = mysql_connect ("localhost", "root", ""); if ($ Con) {//Select database mysql_select_db ("test", $con);//Get the value inside the Get $idid = $_get["id"];//Query database $query = mysql_query ("SELECT ID, Username from user where id= ' $idid ');//database query results are saved to an array (note the second parameter)//MYSQL_ASSOC-associative array//mysql_num-numeric array//Mysql_both-default. Simultaneous generation of associative and numeric arrays $arr = Mysql_fetch_array ($query, MYSQL_ASSOC), $result =array (), $result ["succeed"] = "1"; foreach ($arr as $ Key = $value) {//the key/value is taken out to the data of the result array $result["data"] [$key] = $value;} echo "<pre>"; Echo (Json_encode ($result));} Mysql_close ($con);? >
PHP Simple Get database query results and return JSON