-1
안녕하세요. 내가 무엇을하고 있는지 잘 모르겠습니다. D PHP에서 js를 사용하여 db에서 데이터를 가져 와서 사용자보기 테이블을 만듭니다. 나는 내 모든 에코를 변수 또는 그와 같은 것으로 넣어야한다고 생각한다. 그러나 나는 확실하지 않다. 모든 지원에 감사드립니다.
내 JS의 fucntion 데이터베이스에서 PHP 및 Ajax 데이터 가져 오기
function dataT(){
$.ajax({
type:'Post',
url:'filltable.php',
data:{context :' showusers'},
success:function (data){
$('#content').html(data);
}
});
alert(data);
}
내 HTML 코드
<body onload="dataT()">
<div class="row">
<div class="container">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<h3>tabla</h3>
<br>
<table id="dt" class="table table-hover ">
<thead>
<th>Id</th>
<th>UN</th>
<th>Mail</th>
<th>Actions</th>
</thead>
<tbody id="content">
</tbody>
</table>
</div>
<div class="col-sm-3"></div>
</div>
</div>
내가 PHP를 가져 오는거야됩니다
<?php
$servername = "localhost";
$username = "root";
$password = "";
try {
$conn = new PDO("mysql:host=$servername;dbname=kyo", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if($_POST['context']=='showusers'){
fillT($conn);
}
//end try
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
function fillT(){
$sql = "SELECT `username`, `mail`, id FROM `users` ";
$res = mysqli_query($conn,$sql);
if(!$res){
die("Error!!! ... D:");
}else{
while ($data = mysqli_fetch_assoc($res)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['mail']; ?></td>
</tr>
<?php
}
echo json_encode($data);
}
mysqli_free_result($res);
mysqli_close($conn);
}
?>
PHP로 데이터를 가져오고 있습니까? –
어떻게 PHP 함수를 호출하고 있습니까? –
PHP 코드에 실수가 있습니다. 자세한 정보는 서버 로그를 확인하십시오. –