set_charset("utf8"); //2.search for datatable: books $a1 = $_GET['a1']; $result = $conn->query("select * from books where 書籍名稱 like '%".$a1."%'"); //3.output all the data $alldata = $result->fetch_all(MYSQLI_BOTH); //echo $alldata[0][1]; //4.output to json text from 2d array //若輸出資料有中文會產生亂碼,解決方法:echo json_encode($rows,JSON_UNESCAPED_UNICODE); echo json_encode($alldata,JSON_UNESCAPED_UNICODE); //5.close connection $conn->close(); ?>