我已经想了一个星期了,希望有人能帮我。我在这里问了几个问题,每一个问题我都觉得我离得更近了。这是在没有internet连接的本地计算机上运行的。
我在页面加载时从数据库中提取了几个以cw开头的图像。我还拉其他信息,我可能想在某个时候使用。我想点击图片,然后返回数据库,显示这个人的名字。在下面的例子中,我展示了三张图片,它们的首字母都是cw。我想点击图片并检索每个人的名字。目前,它将只显示第一个人的名字,因为这似乎是一个存储在内存中的初始加载。
具体来说,我需要ajax调用或php代码方面的帮助,因为我不确定错误在哪里。
这是我的test.php,其中包括ajax调用:
<!DOCTYPE html>
<head>
<script src = "../jquery/jquery-3.3.1.js"></script>
<script type="text/javascript">
$("#photo").click(function(){
$.ajax({
type: "POST",
url: "getData.php",
dataType: "html",
success: function(response){
$("#responsecontainer").html(response);
}
});
});
</script>
</head>
<body>
<?php
include_once 'db_connect.php';
$result=$db->query("select * from monctonfir where initials = 'CW'");
if($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
$imageURL = '../image/'.$row["file"];
$initial = $row["initials"];
$name = $row["name"];
$location = $row["location"];
$specialty = $row["specialty"];
?>
<body>
<h3>Employee Details</h3>
<div id="responsecontainer">
<table>
<tr>
<td id="photo">
<a href=""><img id="photo" type="button" src="<?php echo $imageURL ?>"></a>
</td>
</tr>
<tr>
</tr>
</table>
</div>
<?php }
} ?>
/<!--script type="text/javascript">
alert(<?= json_encode($name); ?>);
</script>-->
</body>
</html>
这是我的getdata.php,它执行sql语句:
<?php
include_once 'db_connect.php';
$result=$db->query("select * from monctonfir where file = '$imageURL'");
while ($data = mysqli_fetch_row($result)) {
if($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
$imageURL = 'image/'.$row["file"];
$initial = $row["initials"];
$name = $row["name"];
$location = $row["location"];
$specialty = $row["specialty"];
}
}
}
?>
再次感谢所有的帮助!
暂无答案!
目前还没有任何答案,快来回答吧!