php中带有弹出窗口的Html表
我制作了一个PHP文件,用于查询mysql数据库中的数据,并将结果放入html表中。数据库中的一个字段包含指向文件的链接。一个或多个,用逗号分隔。 一切都很好。在SQL查询中使用:GROUP_concatfilename。 现在是棘手的部分。我试着用。 我的主要目标是——当我点击按钮时,我会看到一个小的弹出窗口,里面有链接。 但我只从表中的第一个结果中得到一个链接。 当我对表格进行排序时,同样的事情也会发生。 下面是我现在从表中得到的小输出:php中带有弹出窗口的Html表,php,html,mysql,twitter-bootstrap-3,Php,Html,Mysql,Twitter Bootstrap 3,我制作了一个PHP文件,用于查询mysql数据库中的数据,并将结果放入html表中。数据库中的一个字段包含指向文件的链接。一个或多个,用逗号分隔。 一切都很好。在SQL查询中使用:GROUP_concatfilename。 现在是棘手的部分。我试着用。 我的主要目标是——当我点击按钮时,我会看到一个小的弹出窗口,里面有链接。 但我只从表中的第一个结果中得到一个链接。 当我对表格进行排序时,同样的事情也会发生。 下面是我现在从表中得到的小输出: 8 Company 1 Address
8 Company 1 Address 12-11/12, City 2017-04-16 12/022 Link
9 Company 2 P. Address 19-M1,City 2020-03-31 15/039 Link
10 Company 3 Address 1,City 2017-04-05 12/015 Link,Link,Link,Link
所以,目标是:按钮,当我点击它弹出窗口将出现与内部链接。
有什么提示可以实现吗?
可能是通过id或类似的方式进行附加查询?可能是这样的
if(isset($_POST['button'])) {
$result = mysqli_query($conn,"SELECT * FROM table WHERE address='.$address' ");
echo "<table>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo '<td> <a href="' . $row['link1'] . '">Link1</a> </td>';
echo '<td> <a href="' . $row['link2'] . '">Link2</a> </td>';
echo '<td> <a href="' . $row['link3'] . '">Link3</a> </td>';
echo "</tr>";
}
echo "</table>";
}
如果您不知道需要回显多少个链接,则需要第二个循环来测试它
<?php
$arr = [
["Company 1", "Address 1,City", "2017-04-05", "12/015", "Link"],
["Company 3", "Address 1,City", "2017-04-05", "12/015", "Link,Link,Link,Link"]
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Example of Bootstrap 3 Modals</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn").click(function(){
$("#myModal").modal('show');
});
});
</script>
<style type="text/css">
.bs-example{
margin: 20px;
}
</style>
</head>
<body>
<div class="bs-example">
<!-- Button HTML (to Trigger Modal) -->
<a href="#" class="btn btn-lg btn-primary">Launch Demo Modal</a>
<!-- Modal HTML -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<table>
<tr>
<th>name</th>
<th>address</th>
<th>date</th>
<th>data</th>
<th>links</th>
</tr>
<tr>
<?php foreach ($arr as $value): ?>
<tr>
<td><?= $value[0]; ?></td>
<td><?= $value[1]; ?></td>
<td><?= $value[2]; ?></td>
<td><?= $value[3]; ?></td>
<td>
<?php if (strpos($value[4], ',') == false AND ! empty($value[4])): ?>
<a href="<?= $value[4]; ?>">link name</a>
<?php else: ?>
<?php $links = explode(',', $value[4]); ?>
<?php foreach ($links as $link): ?>
<a href="<?= $link; ?>">link name</a>
<?php endforeach; ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<table>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
我将创建一个php函数来检索列表id的链接或它应该是什么,并使用显示模型时通过ajax调用单击按钮的项的id调用此函数。这可能会让您感兴趣:.$address看起来像一个打字错误$地址未定义,并希望打开OP to SQL注入。我将根据需要尝试修改和使用它。非常感谢。