b.php (앞단)
<style>
table,th,td {
border:1px solid silver;
border-collapse:collapse;
padding:10px;
}
</style>
<form action="">
<select name="mb_id" onchange="hz(this.value)">
<option value="">아이디 선택</option>
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
</select>
</form>
<div id="txtHint">회원정보 출력위치</div>
<script>
function hz(str) {
var xhttp;
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xhttp.open("GET", "a.php?q="+str, true);
xhttp.send();
}
</script>
a.php (뒷단)
<?php
$mysqli = new mysqli("localhost", "root", "autoset", "mw7"); // DB 연결 (호스트,아이디,비번,DB명)
if($mysqli->connect_error) {
exit('연결 실패');
}
$sql = "SELECT mb_id, mb_name, mb_level, mb_point FROM g5_member WHERE mb_id = ?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $_GET['q']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($mb_id, $mb_name, $mb_level, $mb_point);
$stmt->fetch();
$stmt->close();
echo "<table>";
echo "<tr>";
echo "<th>아이디</th>";
echo "<th>닉네임</th>";
echo "<th>레벨</th>";
echo "<th>포인트</th>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $mb_id . "</td>";
echo "<td>" . $mb_name . "</td>";
echo "<td>" . $mb_level . "</td>";
echo "<td>" . $mb_point . "</td>";
echo "</tr>";
echo "</table>";
?>