3月 20 2015 Web►Overall [Web] 透過PHP取得MySQL資料 上次講過放入,這次講怎麼取出。 PHP程式碼記得要改掉那些名稱,由於是傳給JavaScript,所以利用JSON相當方便。1234567891011121314151617<?php header("Content-type: text/html; charset=utf-8"); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept'); mysql_connect(hostname,username,password); mysql_select_db(databasename); mysql_query("set names utf8"); $q=mysql_query("SELECT * from `databasename`.`tablename` "); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } while($e=mysql_fetch_assoc($q)) $output[]=$e; echo json_encode($output,JSON_UNESCAPED_UNICODE); mysql_close();?> JavaScript程式碼使用jQuery就是這麼簡單。123$.get(URL , function(response) { data = jQuery.parseJSON(response) ; }); Newer [Front-End] Canvas使用滑鼠滾輪縮放 Older [UVa] 10069 - Distinct Subsequences