我正在尝试创建一个由数据库中的数据填充的表。表中的每一行都需要在末尾有一个按钮,该按钮有一个标识"的查询字符串;艺术家"的姓名,并需要链接到该艺术家的特定内容。在我当前的表格中,按钮只是重复的,不是单独的,我不知道如何让它们查询它们所属的艺术家。
<?php
//Query to get artist data
$result = mysqli_query($con,"SELECT * FROM artist LIMIT 10");
if (!$result) {
printf("Error: %s'n", mysqli_error($con));
exit();
}
//show artist data in table
echo "<table><th>BadNoise Artists</th>";
while($row = mysqli_fetch_array($result))
{
echo "<tr><td>" . $row['FirstName'] . "</td><td>" . $row['LastName'] . "</td><td><button>Get External Content</button></td></tr>" ;
}
echo "</table>";
mysqli_close($con);
?>
我使用jQuery来填充div,它将显示每个艺术家的特定内容:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("demo_test.txt");
});
});
</script>
这样的东西应该能起到作用。将艺术家的ID存储在按钮的ID字段中,并通过Jquery:获取
<?php
//Query to get artist data
$result = mysqli_query($con,"SELECT * FROM artist LIMIT 10");
if (!$result) {
printf("Error: %s'n", mysqli_error($con));
exit();
}
//show artist data in table
echo "<table><th>BadNoise Artists</th>";
while($row = mysqli_fetch_array($result)){
echo "<tr><td>" . $row['FirstName'] . "</td><td>" . $row['LastName'] . "</td><td><button id='" . $row['artistId'] . "'>Get External Content</button></td></tr>" ;
}
echo "</table>";
mysqli_close($con);
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var artistId = $(this).attr('id');
$("#div1").load("demo_test" + artistId + ".txt");
});
});
</script>