ページの結果をフィルタリングするために使用したいHTMLフォーム(2つのリストボックスとチェックボックス)があります。
Submit
ボタン( )を押す.onclick(function(){})
と、ローカルサーバー上のPHPスクリプトへのjQuery AJAX呼び出しが実行されるようにするにはどうすればよいですか。最初に、リストボックスで何かが選択されているかどうか、チェックボックスがチェックしてから、それに基づいて SQL ステートメントを作成し、データベースにクエリを実行して、結果を JSON として取得します。
理論的には、どのようにしますか。テーブルからすべてを単純に取得して JSON として保存するための PHP スクリプトが既にあります。
<?php
// databse connection info
require("dbinfo.inc.php");
// try to open a connection to a MySQL server
$connection=mysql_connect($host, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// select the active MySQL database to work with
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// grab data about every campus and which instituion they belong to
$query = 'select statement to grab all the data from a table';
$result = mysql_query($query);
// check if $results has anything
if (!$result) {
die('Invalid query: ' . mysql_error());
}
// time to start generating our huge XML
while ($row = @mysql_fetch_assoc($result)){
$finalarray[] = $row;
$main_arr['products'] = $finalarray;
}
// close connection to the database
mysql_close($connection);
// echo, save and write the file
// print json_encode($main_arr);
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($main_arr));
fclose($fp);
?>