프로그래밍, 코딩
[PHP] ajax와 mysql 연동하기
MorningPhys
2021. 2. 8. 23:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<style> | |
body {font-size:9pt;} | |
table {font-size:9pt;} | |
.none_left_line {border-left-style: none;} | |
.none_right_line {border-right-style: none;border-top-style: none;border-bottom-style: none } | |
.none_line {border-left-style: none;border-right-style: none;border-top-style: none;border-bottom-style: none} | |
</style> | |
<script type="text/javascript"> | |
var xmlhttp | |
function showCustomer(str) | |
{ | |
xmlhttp=GetXmlHttpObject(); | |
if (xmlhttp==null) | |
{ | |
alert ("Your browser does not support AJAX!"); | |
return; | |
} | |
var url="selection.php"; | |
url=url+"?q="+str; | |
url=url+"&sid="+Math.random(); | |
xmlhttp.onreadystatechange=stateChanged; | |
xmlhttp.open("GET",url,true); | |
xmlhttp.send(null); | |
} | |
function stateChanged() | |
{ | |
if (xmlhttp.readyState==4) | |
{ | |
document.getElementById("txtHint").innerHTML=xmlhttp.responseText; | |
} | |
} | |
function GetXmlHttpObject() | |
{ | |
if (window.XMLHttpRequest) | |
{ | |
// code for IE7+, Firefox, Chrome, Opera, Safari | |
return new XMLHttpRequest(); | |
} | |
if (window.ActiveXObject) | |
{ | |
// code for IE6, IE5 | |
return new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
return null; | |
} | |
</script> | |
</head> | |
<body onload='showCustomer("str")'> | |
<table> | |
<tr> | |
<td> 신청자 명 </td> | |
<td> <input type="text" /> </td> | |
</tr> | |
<tr> | |
<td> 예약창구 및 상담시간 </td> | |
<td> | |
<form> | |
Select a Customer: | |
<select name="customers" onchange="showCustomer(this.value)"> | |
<option value="">창구 및 시간 선택</option> | |
<option value="1">1번 창구 09:00 ~ 09:30</option> | |
<option value="2">1번 창구 09:30 ~ 10:00</option> | |
<option value="3">1번 창구 09:00 ~ 09:30</option> | |
<option value="4">1번 창구 09:30 ~ 10:00</option> | |
<option value="5">1번 창구 09:00 ~ 09:30</option> | |
<option value="6">1번 창구 09:30 ~ 10:00</option> | |
</select> | |
</form> | |
</td> | |
</tr> | |
<tr> | |
<td> 예약 가능 여부 </td> | |
<td> <div id="txtHint"> | |
// ajax 를 통한 데이터를 이곳에 불러옵니다. | |
</div> </td> | |
</tr> | |
</table> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$q=$_GET["q"]; | |
// $q = '1'; | |
echo "$q"; | |
$conn = mysqli_connect("localhost", "root", "####","morphys"); | |
// $sql = "SELECT * FROM table1"; | |
$sql="SELECT * FROM table1 WHERE id = '".$q."'"; | |
$result = mysqli_query($conn, $sql); | |
echo("<select name='customers' onchange='showUser(this.value)''>"); | |
while( $row = mysqli_fetch_array($result) ) { | |
if (is_null($row['name'])) { | |
echo ("예약 가능"); | |
echo("<br/>"); | |
echo("<option>".$row['id']."</option>"); | |
} | |
else {echo("예약 불가"); } | |
} | |
echo("</select>"); | |
?> |
728x90
반응형