setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $items = array(); if( isset( $_GET["pref"] ) && !empty( $_GET["pref"]) && $_GET["search"] === "pref" ){ $query = "select * from mountain where pref like '%" . $_GET["pref"] . "%'"; $rows = $db->query( $query ); while( $cols = $rows->fetch() ){ $items [] = array( "name"=>$cols["name"], "height"=>$cols["height"], "pref"=>$cols["pref"]); } } // jsonで出力するという事をヘッダで明示する header('Content-type: application/json'); echo json_encode($items); ?>