これはsearch.jsのコードです`
$('#search').keyup(function () {
var search_term = $(this).val();
$.post('search1.php', { search_term: search_term }, function(data) {
$('#search_results').html(data);
})
; }); `
phpmyadminutf_8で使用します
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-6">
HTMLコードで
これはsearch.phpです
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-6">
<head>
<meta charset="utf-8">
<title>search</title>
<link rel="stylesheet" type="text/css" href="css/style5.css">
</head>
<body>
search name : <input id="search" type="text" />
<div id="search_results"></div>
<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript" src="js/search.js" ></script>
</body>
</html>
これはsearch1.phpです
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-6">
<head>
<meta charset="utf-8">
<title>search</title>
</head>
<body>
<?php
include('connect.php');
if (isset($_POST['search_term'])) {
$search_term = mysql_real_escape_string(htmlentities($_POST['search_term']));
if (!empty($search_term)) {
$search= mysql_query("SELECT name FROM patients WHERE name like '%$search_term%'");
$result_count = mysql_num_rows($search);
$suffix = ($result_count !=1) ? 's' : '';
echo '<p>your search for '.$search_term.' returned '.$result_count.'result'.$suffix.'</p>';
while ($results_row = mysql_fetch_assoc($search)){
echo '<P><strong>'.$results_row['name'].'</strong></p>';
}
}
}
?>
</body>
</html>
ボックスに「ع」と書くと「ع」と表示されます