ページ全体を更新したくない場合は、Javascript/Ajax を使用する必要があります。JQuery では、必要なことを.post()メソッドで非常に簡単に実行できます。
まず、JQuery ファイルを HTML ヘッダーに追加します。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
次に、リクエストを含む .php ファイルを作成します (例: update_owner.php):
<?php
// 1. Connect to your SQL database
// ...
// 2. Get the type
$type = $_POST['type'];
// 3. Perform your query
$results = mysql_query("SELECT * FROM owner where type=".$type);
// 4. Get the only result you want (the first row)
$row = mysql_fetch_array( $results );
// 5. Return the result in json format (assuming that the name
echo json_encode(array("responseCode" => 200, "row" => $row));
次に、いくつかの JavaScript (JQuery を使用) を追加します。
$("select#type").change(function() {
// Get the value of your input field
var type = $(this).val();
// Set the URL
var url = 'update_owner.php';
// Start send the post request
$.post(url,
function(data){
// The response is in the data variable
if (data.responseCode == 200) {
// Write the name in the right cell (with #owner id)
$("#owner").html( data.row.name );
}
else {
// Bad request
}
},"json"
); // Make sure the the response is in json format
return false;
});
それはそれを行う必要があります
PS : 下手な英語で申し訳ありません... 私はフランス人です